You are on page 1of 11

‭print(“”)‬

‭Variables & Data Types‬

‭character_name = “john”‬

‭print(“Hello i'm” John”. ”)‬

‭print(“Hello i'm ” + character_name + ”. ”)‬

‭print(“Hello i'm ” + character_name + ”. ”)‬

‭Character_age = “50.33”‬

‭= 50.33‬

‭is_Male = True‬

‭Working With Strings‬

‭print("Giraffe\"Academy")‬

‭Giraffe”Academy‬

‭print("Giraffe\nAcademy")‬

‭ iraffe‬
G
‭Academy‬

‭ hrase = "Giraffe\nAcademy"‬
p
‭print(phrase)‬

‭ hrase = "Giraffe\nAcademy"‬
p
‭print(phrase + “ is cool”)‬

‭ hrase = "Giraffe\nAcademy"‬
p
‭print(phrase.lower())‬

‭ hrase = "Giraffe\nAcademy"‬
p
‭print(phrase.isupper())‬

‭False‬
‭ hrase = "Giraffe\nAcademy"‬
p
‭print(phrase.upper() .isupper())‬

‭ hrase = "Giraffe Academy"‬


p
‭print(len(phrase))‬
‭15‬

‭ hrase = "Giraffe Academy"‬


p
‭print(prahse[0])‬
‭G‬

‭ hrase = "Giraffe Academy"‬


p
‭print(phrase.index("Aca"))‬
‭5‬

‭ hrase = "Giraffe Academy"‬


p
‭print(phrase.replace("Giraffe","Elephant"))‬
‭Elephant Academy‬

‭Working With Number‬

‭ rint(3+2)‬
p
‭5‬

‭ rint(33*43)‬
p
‭1419‬

‭ rint(3/43)‬
p
‭0.06976744186046512‬

‭ rint(‬‭3‬‭*‬‭(8-2))‬
p
‭18‬
‭print(10 % 3) Remainder‬
‭1‬
‭my_num = 5‬
‭print(my_num)‬
‭5‬

‭ y_num = 5‬
m
‭print(str(my_num)‬
‭5‬
‭ y_num = 5‬
m
‭print(str(my_num) + " is my favourite number")‬
‭5 is my favourite number‬

‭ y_num = -5‬
m
‭print(abs(my_num)) abs = absolute number‬
‭5‬

‭ rint(pow(33, 2)) pow = power‬


p
‭1089‬

‭ rint(max(33, 2)) max = maximum‬


p
‭33‬

‭ rint(min(33, 2)) min = minimum‬


p
‭2‬

‭ rint(round(4.5))‬
p
‭4‬

f‭rom math import * goes down no matter what‬


‭print(floor(4.5))‬
‭4‬

f‭rom math import *‬


‭print(ceil(4.5)) goes up no matter what‬

f‭rom math import *‬


‭print(sqrt(36)) sqrt= square root‬
‭6.0‬

‭Getting Input From Users‬

‭input()‬

‭input("Enter your name: ")‬

‭name = input("Enter your name: ")‬

‭ ame = input("Enter your name: ")‬


n
‭print("hello " + name + "!")‬
‭Enter your name: Zayan‬
‭Hello Zayan!‬
‭ ame = input("Enter your name: ")‬
n
‭age = input("Enter your age: ")‬
‭print("Hello " + name + "! You are " +age +"!")‬

‭ nter your name: Zayan‬


E
‭Enter your age: 12‬
‭hello Zayan! You are 12!‬

‭Building A Basic Calculator‬

‭ um1 = input("Enter a number: ")‬


n
‭num2 = input("Enter another number: ")‬
‭result =int(num1) +int(num2) int= whole numbers only‬

‭print(result)‬

‭ um1 = input("Enter a number: ")‬


n
‭num2 = input("Enter another number: ")‬
‭result =float(num1) +float(num2) float= whole numbers and decimals‬

‭print(result)‬

‭Mad Libs Game‬

‭ olor = input("Enter a color: ")‬


c
‭uncles_name = input("Enter your uncle's name: ")‬
‭favourite_food = input("Enter your favourite food: ")‬
‭print("Roses are " + color)‬
‭print("my uncle's name is " + uncles_name)‬
‭print("Hi I'm the wicked " + favourite_food + "!")‬

‭ nter a color: red‬


E
‭Enter your uncle's name: skeeter‬
‭Enter your favourite food: weiner‬

‭ oses are red‬


R
‭my uncle's name is skeeter‬
‭Hi I'm the wicked weiner!‬

‭Lists‬

‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬

‭ rint(friends[0])‬
p
‭Jason‬

‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬

‭ rint(friends[-1])‬
p
‭Abdul-l‬

‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬

‭ rint(friends[‬‭1:‬‭])‬
p
‭['Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l']‬

‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬

‭ rint(friends[‬‭0:4‬‭])‬
p
‭['Jason', 'Richard', 'Mustafa', 'Arshveer']‬

f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends[1] = "Mike"‬
‭print(friends[0:2])‬

‭['Jason', 'Mike'‬

‭List Functions‬

f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends.extend(lucky_numbers)‬
‭print(friends)‬

[‭'Jason', 'Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l', 2, 4, 6, 14, 15,‬
‭22,]‬

f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends.append("Arjun")‬
‭print(friends)‬

‭['Jason', 'Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l', 'Arjun']‬


f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬
‭friends.insert(1, "Baljot")‬
‭print(friends)‬

‭['Jason', 'Baljot', 'Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l']‬

f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends.remove("Arshveer")‬
‭print(friends)‬

‭['Jason', 'Richard', 'Mustafa', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l']‬

l‭‬
‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬
‭friends.clear()‬
‭print(friends)‬

‭[]‬

f‭riends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬


‭friends.pop()‬
‭print(friends)‬

‭['Jason', 'Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H']‬

‭friends = ["Jason", "Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday", "Abdul-H","Abdul-l"]‬

‭ rint(friends.index("Jason"))‬
p
‭0‬

f‭riends = ["Jason", "Richard","Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday",‬


‭"Abdul-H","Abdul-l"]‬

‭ rint(friends.count("Richard"))‬
p
‭2‬
f‭riends = ["Jason", "Richard","Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday",‬
‭"Abdul-H","Abdul-l"]‬
‭friends.sort() sorts alphabetically‬
‭print(friends)‬

‭['Abdul-H', 'Abdul-l', 'Arshveer', 'Aspandyar', 'Gurjot', 'Jason', 'Mustafa', 'Richard', 'Richard']‬

f‭riends = ["Jason", "Richard","Richard", "Mustafa", "Arshveer", "Gurjot", "Aspanday",‬


‭"Abdul-H","Abdul-l"]‬
‭friends2 = friends.copy‬
‭print(friends)‬

‭['Jason', 'Richard', 'Richard', 'Mustafa', 'Arshveer', 'Gurjot', 'Aspanday', 'Abdul-H', 'Abdul-l']‬

‭Reverse list‬

‭Tuples‬

‭coordinates = (4, 5)‬

‭coordinates = (4, 5)‬

‭ rint(coordinates[0])‬
p
‭4‬

‭Functions‬

‭Def‬

‭def sayhi():‬

‭def sayhi():‬
‭print("Hello fat boy!")‬

‭def sayhi():‬
‭print("Hello fat boy!")‬
‭print("Fat Boy")‬
‭sayhi()‬
‭print("Sorry for calling you fat boy.")‬

‭at Boy‬
F
Hello fat boy!‬

Sorry for calling you fat boy.‬

‭def sayhi(name):‬
‭print("Hello " + name)‬

‭ ayhi("Mike")‬
s
‭sayhi("Steve")‬

‭ ello Mike‬
H
‭Hello Steve‬

‭Return Statement‬

‭def cube(num):‬
‭return num*num*num‬

r‭ esult = (cube(4))‬
‭print(result)‬

‭If Statements‬

i‭s_male = True‬
‭is_tall = False‬

‭if is_male or is_tall:‬


‭print("You are a male or tall or both.")‬
‭else:‬
‭print("You are neither male or tall.")‬

i‭s_male = True‬
‭is_tall = False‬

‭if is_male‬‭and‬‭is_tall:‬
‭print("You are a tall male.")‬
‭else:‬
‭print("You are either not male or not tall or both.")‬
i‭s_male = True‬
‭is_tall = True‬

‭if is_male and is_tall:‬


‭print("You are a tall male.")‬
‭elif is_male and not(is_tall):‬
‭print("You are a short male")‬
‭elif not is_male and is_tall:‬
‭print("You are not a male but are tall")‬
‭else:‬
‭print("You are not male or not tall.")‬

‭If Statements & Comparisons‬

‭def max_num(num1, num2, num3):‬


‭if num1 >= num2 and num1 >= num3:‬
‭return num1‬
‭elif num2 >- num1 and num2 >= num3:‬
‭return num2‬
‭else:‬
‭return num3‬

‭print(max_num(3, 4, 5))‬

‭Build A Better Calculator‬

‭ um1 = float(input("Enter first number: "))‬


n
‭op = input("Enter operator: ")‬
‭num2 = float(input("Enter second number: "))‬

‭if op == "+":‬
‭print(num1 + num2)‬
‭elif op == "-":‬
‭print(num1 - num2)‬
‭elif op == "/":‬
‭print(num1 / num2)‬
‭elif op == "*":‬
‭print(num1 * num2)‬
‭else:‬
‭print("Invalid operator")‬
‭Dictionaries‬

You might also like