DAY 1: 31 JULY 2022
print(5+6+3)
print('5+6+3')
print('DDDDDDDDDDDDD')
print("DDDDDDD\tDDDDDDD",4+3+2,"This is it")
print("\\\\n is for newline")
# \ escape sequence
print("Good Morning",end="! ")
print("How are you", end="? ")
print("I am fine")
print(5+3)
a=5 # sPDSJIJFGDFSJGKDFGM print()
b=3
print(a+b)
a=50
#comment
'''
This is a sample comment
Please ignore
another line of
comment
'''
# Data Types - basic: int, float, str, bool, complex
# int - integer: non decimal values: 8 -5 -4 99 8989999
# float - +/- values with decimal point: 5.0 -5.0 8.989
# str - string "hello" 'morning' '''How''' """Thanks"""
#bool - boolean: True / False
#complex - square root of -1 (i) j in python: 5j: sqrt(-100) 100*-1 = 10j
val1 = 5
print(val1, " : ",type(val1)) #type
val1 = -3.0
print(val1, " : ",type(val1))
val1 = "Hello"
print(val1, " : ",type(val1))
val1 = True
print(val1, " : ",type(val1))
val1 = 4+2j
print(val1, " : ",type(val1))
val2 = 4-2j
print(val1 * val2) #(a+b)(a-b) = a sq - b sq: 16 + 4 = 20 +0j)
a,b,c = 3,8.6,True
print(a,type(b),c)
# 5.6 + 4.4 = 10.0
DAY 2: 1 AUGUST 2022
Download the Python Installer from here (we will install Python 3.9.9):
https://www.python.org/downloads/release/python-399/
Watch installation video from here: https://www.youtube.com/watch?v=mhpu9AsZNiQ
Download & Install IDE for Python Programming
Follow the steps from here: https://learn.swapnil.pw/python/pythonides/
DAY 3: 2 AUGUST 2022
#Basic data types
#int
print("Working with Integer: ARITHEMATIC OPERATIONS")
var1 = 7
var2 = 3
print(var1 + var2) #add
print(var1 - var2) #difference
print(var1 * var2) #multiply
print(var1 / var2) #divide (float value)
print(var1 // var2) #integer divide (only integer part)
print(var1 ** var2) #var1 to the power of var2
print(var1 % var2) #modulo - this gives us remainder
print( 4+5/2+4-5*3+2*5)
print( 5.5)
#float
print("Working with Float now")
var1 = 7.0
var2 = 3.0
print(var1 + var2) #add
print(var1 - var2) #difference
print(var1 * var2) #multiply
print(var1 / var2) #divide (float value)
print(var1 // var2) #integer divide (only integer part)
print(var1 ** var2) #var1 to the power of var2
print(var1 % var2) #modulo - this gives us remainder
#str
print("Working with Strings now")
var1 = 'Good Morning'
var2 = "How are you?"
var3 = '''How are you today?
Whats your plan?
Are you doing well?'''
var4 = """I am fine"""
print(var1)
print(var3)
print(var1 + " "+var2)
print((var1 + " ")* 3)
#bool
var1 = True
var2 = False
#AND OR NOT XOR - operations for boolean values
# AND : If one of the value is False then result will be false
#- otherwise it will True
print("AND OPERATION")
print(True and True)
print(True and False)
print(False and True)
print(False and False)
#Prediction: Rohit and Surya will open the batting
#Actual: Rohit and Pant opened the batting
print("OR OPERATION")
print(True or True)
print(True or False)
print(False or True)
print(False or False)
#Prediction: Rohit or Surya will open the batting
#Actual: Rohit and Pant opened the batting
#complex (imaginary numbers)
print("Working with Complex now")
var1 = 6j
print(var1 **2) #6j*6j = 36* -1= -36 + 0j
print(var1 * var1)
#Comparison Operator: Output is always boolean
print(5 > 6) #False
print(6 < 6) #False
print(5 <= 6) #True
print(6 >= 6) #True
print(6==6) #True
print(5!=5) #False
DAY 4 : AUGUST 3, 2022
#WAP to find the total cost when quantity and price of each item is given
quant = 19
price_each_item = 46
total_cost = price_each_item * quant
print("Total cost for",quant,"quantities with each costing Rs",price_each_item,"is Rs",total_cost)
print(f"Total cost for {quant} quantities with each costing Rs {price_each_item} is Rs {total_cost}")
print(f"Total cost for {quant} quantities with each costing Rs {price_each_item} is Rs {total_cost}")
quant = 3
total_cost = 100
price_each_item = total_cost / quant
print(f"Total cost for {quant} quantities with each costing Rs {price_each_item:0.2f} is Rs {total_cost}")
#Format string values
name = "Kohli"
country = "India"
position = "One Down"
print(f"Player {name:.<15} represents {country:^10} and plays at {position:>10} for international matches")
name = "Ombantabawa"; country = "Zimbabwe"; position = "opener"
print(f"Player {name:<15} represents {country:_^10} and plays at {position:X>10} for international matches")
# Add padding - we will fix the number of spaces for each variable
#logical line v physical line
#; to indicate end of line but its not mandatory
a,b,c,d = 10,20,30,40 #assign multiple values
print(c) #30
print("Hello\nThere")
print("Good Morning",end=". ")
print("How are you?")
# wap to take side of a square as input from the user and perform area and perimeter
#area = sides ** 2
#perimeter = 4 * s
side = input("Enter the side value: ") # is used to take input (dynamic value)
side = int(side) # to convert into integer, we use int(). flot -> float(), string -> str()
print(side, ":",type(side))
perimeter = 4 * side
area = side ** 2
print(f"Square of {side} has a perimeter of {perimeter} and the area is {area}")
## Use input() and formatting for below assignments
#1. Input the length and breadth of a rectangle and calculate area and perimeter
#2. Input radius of a circle and calculate area and circumference
DAY 5: AUGUST 4, 2022
#Conditions - IF, IF-ELSE, IF - ELIF - ELSE, IF - ELIF............ ELSE
avg = 40
#if avg > 50: pass
if avg >50:
print("Congratulations")
print("You have passed")
print("Great job")
else:
print("Sorry, you have failed")
# avg > 70: Grade A, avg > 50 B ;
avg = 60
if avg >=70:
print("Grade A")
elif avg >=50:
print("Grade B")
else:
print("Grade C")
#Avg > 80: A, 70: B, >60: C, >50: D, 40: E, <40: F
avg = 90
#Nested IF- if inside another if
if avg>=80:
if avg >=90:
print("AWESOME PERFORMANCE")
if avg >=95:
print("You win Presidents Medal")
print('grade A')
elif avg>=70:
print('grade B')
elif avg>=60:
print('grade C')
elif avg>=50:
print('grade D')
##########3
avg=90
if avg>=80:
print ('grade A')
elif avg>=70:
print('grade B')
elif avg>=60:
print('grade C')
elif avg>=50:
print('grade D')
elif avg>=40:
print('grade E')
else:
print('grade F')
#WAP to check if a person is eligible to vote in India or not
#Age >=18 then you will check nationality - yes
age = 18
nationality = "indian"
if age >=18:
if nationality =="Indian":
print("You are eligible to vote in India")
else:
print("Sorry, only Indians are eligible to vote")
else:
print("Sorry you do not meet the required criteria")
age =20
if age>=18:
print(" awesome you are eiligble to vote ")
#Assignment: Take 3 numbers and print the highest, second highest and the lowest value
DAY 6: 11 AUGUST 2022
#Strings
val1 = "Hello"
val2 = 'Good Morning'
val3 = '''Hello
how are
you'''
val4 = """I am fine thank you"""
# what's your name?
print("what's your name?")
print('what\'s your name?') #escape character - \ it works only for 1 character after
print("\\n will give new line")
print("\\\\n will give new line")
val1 = "Hellodsogjidaoioadpif orgpoaitpoaigtpoafdifgpo poergpadigpifgpi igopigof oprgiodfigdofig"
#indexing /slicing - []
print(val1[0]) #first character
print(val1[4])
print(len(val1))
tot_char = len(val1)
print(val1[tot_char - 1]) #last character
print(val1[tot_char - 3]) #3rd last character
print(val1[- 1]) #last character
#series of characters in continuation
val1 = "GOOD DAY"
print(val1[5:8])
print(val1[0:4])
print(val1[:4])
#negative indexes
print(val1[-5:-2])
print(val1[-7:-5])
print(val1[-3:]) #DAY
print(val1[:]) #DAY
Day 7 – AUGUST 16 , 2022 STRING -2 and Basic Intro to IF Condition
#Methods in String
txt1 = "Good Morning"
print(txt1[-5:-1])
#len(txt1)
fname="Sachin"
print(fname.isalpha())
print(fname.isupper()) #SACHIN
print(fname.islower()) #sachin tendulkar
print(fname.istitle()) #Sachin Tendulkar
print(fname.isdigit())
print(fname.isalnum())
print(fname.upper())
print(fname.lower())
print(fname.title())
fname = "Sachin Tendulkar" #input("Enter your name: ")
print(fname.upper().count("S"))
print(fname.upper().count("S",1,7))
txt1 = "First Second Thirty first thirty fifth sixty first sixty ninth"
print("Total first are: ",txt1.upper().count("ST "))
print(fname.lower().index("ten"))
print(fname.lower().replace("ten","eleven"))
############# IF Condition ###########
fname = "Sachin Tendulkar"
ten_count = fname.lower().count("ten")
print(ten_count)
if ten_count >0:
print("Counting the number of ten(s)")
print(fname.lower().index("ten"))
print("Thank You")
DAY 8 : AUGUST 18 , 2022
# Conditions
avg = 30
if avg >=40:
print("You have passed")
print("Congratulations")
else:
print("I am in else")
print("Sorry, you havent passed")
print("Thank you")
num = 0
if num >0:
print(f"{num} is positive")
elif num==0:
print("Zero is neither positive or negative")
else:
print(f"{num} is negative")
### Take marks in 5 subjects, calculate total and avg, based on avg assign grades
marks1 = int(input("Enter marks in subject 1: "))
marks2 = int(input("Enter marks in subject 2: "))
marks3 = int(input("Enter marks in subject 3: "))
marks4 = int(input("Enter marks in subject 4: "))
marks5 = int(input("Enter marks in subject 5: "))
total = marks1 + marks2 + marks3 + marks4 + marks5
avg = total / 5
print(f"Student has scored total marks of {total} and average of {avg}")
#avg>=80: A, avg>=70: B, avg>=60: C, avg>=50: D, avg>=40: E, avg<40: Failed
#avg >=90: win school medal / avg>95: President Medal
if avg>=80:
print("You have scored Grade A")
if avg>=90:
if avg>=95:
print("You win President Medal")
else:
print("You win School Medal")
elif avg>=70:
print("You have scored Grade B")
elif avg>=60:
print("You have scored Grade C")
elif avg>=50:
print("You have scored Grade D")
elif avg>=40:
print("You have scored Grade E")
else:
print("You have scored Failed Grade")
if avg>=35:
print("You just missed, try harder next time")
elif avg>=20:
print("Please study hard")
else:
print("You are too far behind")
##########
#WAP to find the bigger of the 2 numbers
num1,num2 = 30,50
if num1>=num2:
print(f"{num1} is greater than or equal to {num2}")
else:
print(f"{num2} is greater than {num1}")
#WAP to find the bigger of the 3 numbers
num1,num2,num3 = 90,50,140
b1 = num1
if num1>=num2: #between num1 and num2 we know num1 is greater
if num1 >= num3:
b1=num1
else: #num1 >num2 and num3 > num1
b1=num3
else: #num2 is greater than num1
if num2 > num3:
b1=num2
else: #num1 >num2 and num3 > num1
b1=num3
print(f"{b1} is greatest")
## get the order of 3 numbers (decreasing order)
num1,num2,num3 = 9,50,40
b1,b2,b3 = num1,num1,num1
if num1>=num2: #between num1 and num2 we know num1 is greater
if num1 >= num3:
b1=num1
if num2 >=num3:
b2,b3=num2, num3
else:
b2, b3 = num3, num2
else: #num1 >num2 and num3 > num1
b1,b2,b3=num3,num1,num2
else: #num2 is greater than num1
if num2 > num3:
b1=num2
if num1>=num3:
b2,b3=num1,num3
else:
b2, b3 = num3, num1
else: #num1 >num2 and num3 > num1
b1,b2,b3=num3,num2,num1
print(f"{b1} >= {b2} >= {b3}")
DAY 9: AUGUST 20, 2022
#Loops : repeat set of lines of code multiple times
# for - for loop when we know how many times
# while - used for repeatition based on conditions
for i in range(0,5,1): #generate values starting from zero upto 5(excluded), increment is 1
print(i+1)
for i in range(2,15,4): #generate values starting from 2 upto 15(excluded), increment is 3
#print(i+100) #3,7,11, 15
print("Hello")
for j in range(3,7): #start & end - default is increment = 1
print(j)
for i in range(4): #its ending value, default is start(=0) & increment (=1)
print(i+1)
n = 5
for i in range(n):
print("*",end=" ")
'''
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
'''
print("\n2...........")
for j in range(n):
print()
for i in range(n):
print("*",end=" ")
print()
'''
*
* *
* * *
* * * *
* * * * *
'''
print("\n3...........")
for j in range(n):
print()
for i in range(j+1):
print("*",end=" ")
print()
'''
* * * * *
* * * *
* * *
* *
*
'''
print("\n4...........")
for j in range(n):
print()
for i in range(n-j):
print("*",end=" ")
print()
#Assignment
'''
*
* *
* * *
* * * *
* * * * *
'''
DAY 10: AUGUST 21, 2022
DAY 13 : AUGUST 27, 2022
DAY 14 : AUGUST 28, 2022
DAY 15 : AUGUST 29, 2022
### Assignment – rewrite the below program by using list
#wap to arrange given 3 numbers in increasing order
#enter numbers as: 45, 75, 35 => 35 45 75
a,b,c = 85, 75,95
l1,l2,l3 = a,a,a
if a < b: #when a is less than b
if a<c: # a is less than b and a is less than cv [
l1 = a
if b<c:
l2,l3=b,c
else: #c is less than b
l2,l3 = c,b
else: #a is less than b and greater than c [e.g. 3 5 2]
l1,l2,l3=c,a,b
else: #when b is less than a
if b <c:
l1 =b
if a <c:
l2,l3=a,c
else:
l2,l3 = c,a
else: # c <b
l1,l2,l3 = c,b,a
print(f"{l1} <= {l2} <={l3}")
DAY 16: SEPTEMBER 3, 2022
#Dictionary
list1 = [4,5,6,7] #automatic position
dict1 = {"Harsh": 8.4,"Manish":8.12}
print(dict1["Harsh"])
#update to add another dictionary
dict2 = {"Sachin": 5.6, "Laxman": 7.2}
dict1.update(dict2)
print(dict1)
# FUT, QY, HY, SUT, FI (5%, 20%, 25%, 5%, 45%)
all_info ={}
for i in range(2): #2 students
name = input("Enter Name: ")
main_list=[] #list of list
for k in range(5): # 5 types of exams
t_list = []
for j in range(3):
marks = int(input("Enter marks: "))
t_list.append(marks)
main_list.append(t_list)
t_dict = {name: main_list}
all_info.update(t_dict)
#{“Manish”: [[],[],[],[],[]]} – final output template
#Now we have the data
#to get all the keys:
keys = all_info.keys()
values = all_info.values()
items = all_info.items() # (key, value)
apply_std = [5, 20, 25, 5, 45]
#updated marks will be stored in another dictionary:
final_marks ={} #{name: []}
for k,v in all_info.items(): #[[5,7,8],[55,55,55],[66,66,66],[9,8,7],[88,88,88]]
updated_marks=[]
for i in range(3): #3 subjects ke liye
add = 0
for j in range(5): #5 exams
add = add + v[j][i] * apply_std[j]/100 #v[0][0] * apply[0] + v[1][0]* apply[1] +
updated_marks.append(add)
final_marks.update({k:updated_marks})
DAY 17: 11 SEP 2022
#Function
def mystatements():
print("Hello")
print("How are you doing?")
print("Good morning")
def mystatements2(name,greeting): #required & positional
print("Hello",name)
print("How are you doing?")
print(greeting)
def mystatements3(name, greeting="Good Morning"): #default & positional
#name is required and greeting is default
#required parameters are given before default
print("Hello",name)
print("How are you doing?")
print(greeting)
return 100
mystatements()
result = mystatements2("Sachin","Good Morning")
print(result) #None is returned
result = mystatements3("Sachin")
print(result)
#function to take 2 numbers as input and
# perform add, sub,multiplication & division
# create - 2 functions: 1)required positional
# 2)default wheren numbers are 99 & 99
#return 4 answers as tuple