Skip to content

Instantly share code, notes, and snippets.

@shinysu
shinysu / 0_lists.py
Last active November 18, 2020 12:26
Examples & exercises using list
'''
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_Session5.py
Last active November 13, 2020 13:37
programs using loops
'''
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 / 0_Session3.py
Last active October 30, 2020 05:53
Simple programs
'''
print a string
'''
print("hello!")
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
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 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 ={}
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)
@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)
@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 / 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))