Learning ML – July 2022 by Digital

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

Click here to Watch the Video Day 1

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/

You can follow the instructions to install from here:
http://learn.swapnil.pw/python/pythoninstallation/


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

 

#While
##repeat block of code

 

n=1
while n<=5:
    print(n)
    n+=1

 

#wap to read marks in 3 subjects and calculate sum and average till user want
choice = “y”

 

while choice==“n”#entry check is not important
    sum=0
    for i in range(3):
        marks = int(input(“Enter the marks in subject “+str(i+1)+“: “))
        sum+=marks
    avg = sum/3
    print(f“Sum is {sum} and average is {avg})
    choice = input(“Type y to continue, anyother key to stop: “)

 

# instances where entry check is not important, you can create infite loop
while True#entry check is not important
    sum=0
    for i in range(3):
        marks = int(input(“Enter the marks in subject “+str(i+1)+“: “))
        sum+=marks
    avg = sum/3
    print(f“Sum is {sum} and average is {avg})
    choice = input(“Type y to continue, anyother key to stop: “)
    if choice!=‘y’:
        break

 

#wap to generate numbers between given input values
sn = int(input(“Enter the start number: “))
en = int(input(“Enter the end number: “))
for i in range(sn,en+1):
    print(i, end=”   “)
print()

while sn <= en:  #entry check is important
    print(sn, end=”   “)
    sn+=1
print()

#Assignment 1: WAP to check if a number is prime or not
#Assignment 2: WAP to generate first 10 multiples of given value

 

DAY 11: AUGUST 22, 2022
 

 

#wap to read menu options
import getpass
dict_username = {}
while True:
    print(“Select your options: “)
    print(“1. Register \n2. Add Member\n3. Add Books\n4. Issue Books \n5. Return Books”)
    print(“6. Display Username”)
    print(“\n11. Quit”)


    ch=int(input(“Your Option: “))
    if ch==1:
        uname = input(“Enter username: “)
        passwd = getpass.getpass(“Enter Password: “)  #input(“Enter password: “)
        t_dict = {uname:passwd}
        dict_username.update(t_dict)
    elif ch==2:
        pass
    elif ch==3:
        pass
    elif ch==4:
        pass
    elif ch==5:
        pass
    elif ch==11:
        break
    elif ch==6:
        #Displaying username
        print(“Usernames are:”)
        for i in dict_username.values():
            print(i)
    else:
        print(“Invalid option! Please try again…  “)
        continue


    print(“Your Option has been successfully completed!”)

#wap to guess the number thought by the computer
import random
comp_num = random.randint(1,100#int(input(“Enter a number: “))
counter = 0
while True:
    guess_num = int(input(“Guess the number: “))
    counter+=1
    if guess_num == comp_num:
        print(f“You have guessed the number correctly in {counter} attempts!”)
        break
    else:
        print(“You have not correctly guessed the number!”)
        if guess_num > comp_num:
            print(“HINT: You have guessed a higher number!!!”)
        else:
            print(“HINT: You have guessed a lower number!!!”)
    
#wap to guess the number thought by the computer
import random
comp_num = random.randint(1,100#int(input(“Enter a number: “))
counter = 0
low,high=1,100
while True:
    guess_num = random.randint(low,high) #int(input(“Guess the number: “))
    counter+=1
    if guess_num == comp_num:
        print(f“You have guessed the number {comp_num} correctly in {counter} attempts!”)
        break
    else:
        print(f{guess_num} is not correct”)
        if guess_num > comp_num:
            #print(“HINT: You have guessed a higher number!!!”)
            high = guess_num-1
        else:
            #print(“HINT: You have guessed a lower number!!!”)
            low = guess_num+1
    

#wap to guess the number thought by the computer
import random
comp_num = random.randint(1,100#int(input(“Enter a number: “))
counter = 0
low,high=1,100
while True:
    guess_num = (low+high)//2  #random.randint(low,high) #int(input(“Guess the number: “))
    counter+=1
    if guess_num == comp_num:
        print(f“You have guessed the number {comp_num} correctly in {counter} attempts!”)
        break
    else:
        print(f{guess_num} is not correct”)
        if guess_num > comp_num:
            #print(“HINT: You have guessed a higher number!!!”)
            high = guess_num-1
        else:
            #print(“HINT: You have guessed a lower number!!!”)
            low = guess_num+1
Day 12: AUGUST 25 2022 – STRING – 2 and LIST – 1

 #Strings
txt1 = “Hello”
txt2 = ‘Good Morning Good Day’
txt3 = ”’How are you?
where are you going
when will you be back”’
txt4 = “””I am fine
I am going to school
I will be back in the evening”””
print(type(txt1), type(txt2),type(txt3),type(txt4))
print(txt3)
print(txt2)

print(txt1 + txt2)
print(“7” + “8”)
print(txt1 * 4)
num = 78
num = int(str(78)*4)
print(num)
print(“Fine” in txt4) #membership test
for i in txt1:
    print(i, end=” “)
print()

txt1 = “Good Morning”
#Strings are immutable
#txt1[0]=”H” – you cant edit/ overwrite
txt1 = “H” + txt1[1:]
print(txt1)
#reverse the text
reverse_str = “”
for i in txt1:
    reverse_str = i+reverse_str
print(“Reversed String: “,reverse_str)

given_txt = “Sachin;Kohli;Rohit;Kapil;Dhoni;”
if “;” in given_txt:
    given_txt = given_txt.replace(“;”,” “)
    print(given_txt)
else:
    print(“Sorry, text doesnt have : as separator”)

# WAP to read a string and find sum of all the numbers only 
#and keep doing till you find single number
txt1 = “sifdsdi43250934ur934ur09csdi43250934ur09c”

while len(txt1)!=1:
    sum=0
    for i in txt1:
        if i.isdigit():
            sum+=int(i)
    txt1 = str(sum)

print(“Final Sum is “,sum)

#List”
list1 = [2,4,5.5,“Hello”True,[3,6,9]]
print(type(list1))
print(len(list1))
print(list1[0])
print(list1[-1])
print(list1[-3:-1])
print(list1[-2:])
print(type(list1[-2]))
print(list1[-3][-3:])
print(list1[1]+list1[0])
list2 = [4,8,12]
print(“list addition: “,list1 +list2)
for i in list2:
    print(i)

##############
list1 = []
#adding members using append
list1.append(5#added at the back
list1.append(15)
list1.append(25)
list1.append(35)
print(list1)
#adding using insert(position,value)
list1.insert(1,10)
list1.insert(3,20)
print(list1)

#WAP a program to read marks of 5 students and calculate
sum=0
marks = []
for i in range(5):
    m = int(input(“Enter marks for subject “+str(i+1)+“: “))
    sum+=m
    marks.append(m)
print(f“Marks obtained are {marks} and the total is {sum})

# modify the above program to read marks of 5 students
#all_marks = [[],[],[],[]]

DAY 13 : AUGUST 27, 2022

#27 AUGUST 2022

list1 = []
print(len(list1))
#append() – adds at the last
#insert() – inserts at given position
#pop() – removes from given position
#remove() – removes given value

#Queues: First In First Out (FIFO)
my_queue = []
while True:
    print(“Select following options:”)
    print(“1. Display the content of the Queue\n2. Add a new member”)
    print(“3. Remove the member\n4. Exit”)
    ch=input(“Ënter your choice:”)
    if ch==“2”:
        inp = input(“Enter the member to be added: “)
        my_queue.append(inp)
    elif ch==“3”:
        if len(my_queue)<=0:
            print(“Sorry, there is no one in the queue!”)
            continue
        my_queue.pop(0)
    elif ch==“1”:
        print(“Current members in the queue: \n”,my_queue)
    elif ch==“4”:
        break
    else:
        print(“Invalid Option, try again!”)
#Stack: Last In First Out (LIFO)

#Implement Stack as assignment

#Strings are immutable
str1 = “Hello”
#str1[1]= “E”
list1 = [“H”,“E”,“L”,“L”,“O”]
list1[1] = “K”
print(list1)
#Lists are MUTABLE
list1 = [“H”,“E”,“L”,“L”,“O”]
list2 = list1   #shallow copy
list3 = list1.copy()   #deep copy
print(“1. List 1”, list1)
print(“1. List 2”, list2)
print(“1. List 3”, list3)
list1.append(“K”)
list2.append(“L”)
list3.append(“M”)
print(“2. List 1”, list1)
print(“2. List 2”, list2)
print(“2. List 3”, list3)

list3.clear()
print(list3)
del list3  #delete the variable
#print(list3)
count = list1.count(“L”)
print(count)
list3 = list1 + list2
#list1 = list1 + list2
list1.extend(list2)
print(list1)
print(list1.index(“O”))
#index can take 2 other values:
## 1. start value-it will search in the string after this index
## 2. end value – search till this index
value_to_search = “L”
count = list1.count(value_to_search)
print(f“The indexes of {value_to_search} are: “,end=“”)
start_search = 0
for i in range(count):
    ind = list1.index(value_to_search,start_search)
    print(ind,end=”  “)
    start_search= ind + 1
print()
# reverse() – reverse the list  values
list1.reverse()
print(list1)
list1.sort()
print(list1)
#list1.reverse()
list1.sort(reverse = True)
print(list1)

 

DAY 14 : AUGUST 28, 2022

 

#TUPLE
#Its immutable version of list
t1 =(3,5,7,9,11,3,5,7,9,3,5)
print(type(t1))
print(t1.count(7))
print(t1.index(5))

t1 = list(t1)
t1=()
t2=(2,3)
#just one value in tuple:
t3 = (3,)

if (23,54) > (23,54,99,89):
  print(23,54)

#unpacking
t1 = (3,5,7)
a,b,c = t1
print(a,b,c)


#Dictionary
dict1 = {9:“Sachin”“Name”“Rohit”True : “Cricket”}
#key can be anything but they have to be unique
print(dict1[True])
temp = {5.6“Mumbai”}
dict1.update(temp)

print(dict1)
#wap to input marks in 3 subjects and save under rollno
all_info = {}
for i in range(3):
  temp_dict ={}
  t_list = []
  rollno = int(input(“Enter the Roll No.: “))
  for j in range(3):
    m = int(input(“Enter the marks: “))
    t_list.append(m)
  temp_dict = {rollno: t_list}
  all_info.update(temp_dict)

print(“Marks of all students are: “,all_info)

all_info = {101: [767869], 102: [985671], 68: [528988]}
print(all_info.keys())
print(all_info.values())
print(all_info.items())

for i,j in all_info.items():
  print(i,” : “,j)


 

DAY 15 : AUGUST 29, 2022


#WAP where we input date, month and year in numbers
# and display as – date(st/nd/rd/th) Month_in_text Year
# eg. date = 25  month = 8 year = 2022
# output would be 25th August 2022
month_txt = [‘January’‘February’,‘March’,‘April’,‘May’,
             ‘June’‘July’,‘August’,‘Setember’,‘October’,
             ‘November’‘December’]
date_th = [‘st’,‘nd’,‘rd’] + 17*[‘th’] + [‘st’,‘nd’,‘rd’] +7*[‘th’] +[‘st’]
date = int(input(“Enter the Date: “))
month = int(input(“Enter the Month: “))
year = input(“Enter the Year: “)
result = str(date)+date_th[date-1]+” “ + month_txt[month-1]+” “ + year
print(result)


#Assignment: input marks of 5 subjects for 5 students and display
#the highest marks in each subject and also for overall and name the student


### 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