Skip to content

Instantly share code, notes, and snippets.

@shinysu
shinysu / 0_Day5.py
Created September 4, 2020 14:59
Day5 examples
'''
using for loop to print numbers 1 to 10
range(a, b+1) starts from a and ends at b
'''
for i in range(1, 11):
print(i)
@shinysu
shinysu / Day7.py
Created September 10, 2020 16:32
day7 examples
'''
check if an element is present in the list
you can use 'in' operator to check if the element is present and 'not in' operator to check if the element is not present
'''
cart = ['ice cream', 'chocolates', 'bread', 'jam', 'butter']
item = input("Enter the element you want to search: ")
if item in cart:
print("yes, the element is present")
@shinysu
shinysu / 0_Strings.py
Last active November 2, 2020 08:20
Programs on strings
'''
program that concatinates all letters in prefixes to the suffix
'''
prefixes = 'JKLMNOPQ'
sufix = 'ack'
for letter in prefixes:
print(letter + sufix)
@shinysu
shinysu / 0_Dictionary.py
Last active November 5, 2020 14:09
Dictionaries
'''
A sample dictionary
'''
birthdays = {'Arun': '01-09-2002', 'Ben': '08-12-2001', 'Cathy': '21-04-2001'}
print(birthdays)
print(type(birthdays))
print(len(birthdays))
@shinysu
shinysu / 0_files.py
Last active November 21, 2020 13:54
Files
'''
program to read from a file using read() and write to another file using write()
'''
with open("input.txt","r") as reader:
lines = reader.read()
with open("output.txt","w") as writer:
writer.write(lines)
@shinysu
shinysu / 00_Forge_day1.py
Last active September 30, 2020 00:35
session1 - python turtle
'''
draw a line using turtle
'''
import turtle
t = turtle.Turtle()
t.forward(100)
import os
import datetime
file_data ={}
todaysDate = datetime.datetime.today()
def get_all_files(filepath):
for (root, directories, files) in os.walk(filepath):
for name in files:
file = os.path.join(root, name)
import os
import datetime
file_data ={}
todaysDate = datetime.date.today()
def get_all_files():
for (root, directories, files) in os.walk(filepath):
for name in files:
file = os.path.join(root, name)
import os
import datetime
file_data ={}
todays_date = datetime.date.today()
def get_all_files():
for (root, directories, files) in os.walk(filepath):
for name in files:
file = os.path.join(root, name)
import pgzrun
from random import randint
WIDTH = 800
HEIGHT = 600
BLACK = (0, 0, 0)
paddle = {"x": 20, "y": HEIGHT-50, "length": 200, "width":25}
ball = {"x": 0, "y": 0, "move_x": 5, "move_y": 5}
BALL_RADIUS = 25