This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
program that concatinates all letters in prefixes to the suffix | |
''' | |
prefixes = 'JKLMNOPQ' | |
sufix = 'ack' | |
for letter in prefixes: | |
print(letter + sufix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A sample dictionary | |
''' | |
birthdays = {'Arun': '01-09-2002', 'Ben': '08-12-2001', 'Cathy': '21-04-2001'} | |
print(birthdays) | |
print(type(birthdays)) | |
print(len(birthdays)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a line using turtle | |
''' | |
import turtle | |
t = turtle.Turtle() | |
t.forward(100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |