My python practice lesson 1 Date:
21-2-2023
Day:
Tuesday
Name:
[Link] shri
print("Hello world!")
Hello world!
print ("I am studying in olympisd international school")
I am studying in olympisd international school
E-mail = input ("Enter your E-mail address: ")
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
e-mail = input ("Enter your E-mail address: ")
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
email = input ("Enter your E-mail address: ")
Enter your E-mail address: .......@[Link]
print ("Pls confirm that your E-mail address is correct:",)email
SyntaxError: incomplete input
print ("Pls confirm that your E-mail address is correct:" , email)
Pls confirm that your E-mail address is correct: .......@[Link]
print ("I am a student" , "who likes python!"sep = ','
SyntaxError: invalid syntax. Perhaps you forgot a comma?
print ("I am a student" , "who likes python!"sep = ','
SyntaxError: invalid syntax. Perhaps you forgot a comma?
print ("I am a student , who likes python!"sep = ','
SyntaxError: invalid syntax. Perhaps you forgot a comma?
print ("I am a student" , "who likes python!" sep = ','
SyntaxError: invalid syntax. Perhaps you forgot a comma?
print ("I am a student"),("who likes python")
I am a student
(None, 'who likes python')
print ("I am a student"),("who likes python")sep=','
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
print ("I am a student"),("who likes python")sep = ','
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
Python practice - lesson 2
Date: 21-3-2023
Day:Tuesday
Name:[Link] shri
student_name = "Gunanthra"
print ("my name is",student_name)
my name is Gunanthra
a = "Welcome to python"
print (a, student_name, sep = ",")
Welcome to python,Gunanthra
print (a,student_name,sep = ", ")
Welcome to python, Gunanthra
print (a,student_name)
Welcome to python Gunanthra
4+2
6
28/7
4.0
___________________________________________________________________________________
_______________________________
script:
a=int(input("Enter your age:"))
b=int(input("Enter current year:"))
print ("You are born in the year",b-a)
output:
Enter your age:12
Enter current year:2023
You are born in the year 2011
___________________________________________________________________________________
______________________________
word="welcome to olympiad international school"
print ([Link]())
WELCOME TO OLYMPIAD INTERNATIONAL SCHOOL
print ([Link]())
welcome to olympiad international school
print ([Link](' '))
['welcome', 'to', 'olympiad', 'international', 'school']
word=[Link]('school', 'campus')
print (word)
welcome to olympiad international campus
___________________________________________________________________________________
____________________
script:
word="welcome to olympiad international school"
print (word[4])
output:
o
script:
word="welcome to olympiad international school"
print (word[8])
output:
t
___________________________________________________________________________________
_______________________________
Lesson 3
Date:28/3/2023
Day:
Tuesday
Name:
[Link] shri
String methods
string2 = 'jennie'
string2 = [Link]('ie','y')
print(string2)
jenny
print([Link]())
JENNY
print([Link]())
jenny
stringreverse = ''.join(reversed(string2))
print(stringreverse)
ynnej
print([Link]('n'))
['je', '', 'y']
print([Link]('e'))
['j', 'nny']
string2 = 'Alexander'
print(string2)
Alexander
string2 = 'Gunanthrashri'
print(string2)
Gunanthrashri
String Slicing
print(string2[0:2])
Gu
print(string2[1:4])
una
String Striding
str1 = 'welcome to programming'
print(str1[2:10])
lcome to
print(str1[::2])
wloet rgamn
print(str1 [Link])
wloet
String Strip
str1 = 'welcome to programming'
print([Link]())
welcome to programming
String Addition / Concatenation
name = input("What is your name?")
What is your name? Gunanthra
print(name + " is the best")
Gunanthra is the best
name[0]"K" #immutable
print("n" in string2)
True
print ("j" in string2)
False
print ("a" in string2)
True
Arithmetic Operators
print ("we are going to work on the arithmetic operators in this programe")
print ("Add 3+4 = ",3+4)
print ("Multiply 3*4 = ",3*4)
print ("Subtract 13-4 = ",13-4)
print ("Divide 12/4 = ",12/4)
print("Modulus 12%4 = ",12%4)
we are going to work on the arithmetic operators in this programe
Add 3+4 = 7
Multiply 3*4 = 12
Subtract 13-4 = 9
Divide 12/4 = 3.0
Modulus 12%4 = 0
___________________________________________________________________________________
_______________________________
Lesson 4
Date:3-4-
2023
Day: Tuesday
Assignment operator
a = int(input('Please enter the value of a'))
b = int(input('Please enter the value of b'))
c = a + b
print ("Line 1 - Value of c is ",c)
c += a #this is same as c = c+a
print ("Line 2 - Value of c is ",c)
c *= a #this is same as c = c*a
print ("Line 3 - Value of c is ",c)
c /= a #this is same as c = c/a
print ("Line 4 - Value of c is ",c)
c %= a #this is same as c = c%a
print ("Line 5 - Value of c is ",c)
Logical operators
print ("Work on the logical operators!")
#typecast means to convert one data type to another type.
x=int(input("Please enter the number"))
if ((x>0 and x<=50)or(x>50 and x<=10000000)):
print ("You have chosen a number which is smaller than 10000000")
if (not(x<=10000000)):
print ("You have chosen a number which is greater than 10000000")
Lists are used to store multiple items in a single varible
print(len(numlist)
List
Data type string works like a list:
# Declare a variable 'studentname'.
studentname= 'Alexander'
print (studentname[0])
print (studentname[])
___________________________________________________________________________________
_____________________________
Lesson 5
Date:11-4-2023
Day:Tuesday
#Declare a variable classlist.
classlist=['Alan', 'Ben','Ann']
[Link]('Jane')
print (classlist)
['Alan', 'Ben', 'Ann', 'Jane']
[Link] (['Peter','Tom'])
print (classlist)
['Alan', 'Ben', 'Ann', 'Jane', 'Peter', 'Tom']
[Link](1,'Lee')
print(classlist)
['Alan', 'Lee', 'Ben', 'Ann', 'Jane', 'Peter', 'Tom']
[Link] ('Jane')
print (classlist)
['Alan', 'Lee', 'Ben', 'Ann', 'Peter', 'Tom']
del classlist [2:4]
print (classlist)
['Alan', 'Lee', 'Peter', 'Tom']
#Declare a variable popped_item
popped_item=[Link]()
print (classlist)
['Alan', 'Lee', 'Ben', 'Ann', 'Jane', 'Peter']
print (popped_item)
Tom
#List can be sorted.
[Link]()
print (classlist)
['Alan', 'Ann', 'Ben', 'Jane', 'Lee', 'Peter']
[Link]()
pirnt (classlist)
['Peter', 'Lee', 'Jane', 'Ben', 'Ann', 'Alan']
print (range(10))
range(0, 10)
print (list(range(10)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(list(range(2, 8)))
[2, 3, 4, 5, 6, 7]
print(list(range(2, 20, 3)))
[2, 5, 8, 11, 14, 17]
For Loop
for x in range(0,10):
print (x)
0
1
2
3
4
5
6
7
8
9
for x in range(1,10):
print (x)
1
2
3
4
5
6
7
8
9
for x in range(1,11,2):
print (x)
1
3
5
7
9
For loop in a list
input:
digits = [0, 1, 5]
for i in digits :
print(i)
else:
print ("No items left.")
output:
0
1
5
No items left.
____________________________________________________________________
Lesson 6
Date: 18/4/2023
Day: Tuesday
input:
digits = [3,4,5,6,7,8,9]
for g in digits:
print (g)
else:
print ("List completed")
output:
3
4
5
6
7
8
9
List completed
input:
fruits = ['apple','orange','pineapple']
#iterate - (repeat) over the list using index
for i in range (len(fruits)):
print ("I like",fruits[i])
output:
I like apple
I like orange
I like pineapple
input:
#creating a list
List = [11,5,17,18,20,23,43,75]
#iterate each element in list
#and add them to a variable total
#ele is the index/counter
for ele in range (0,len(List)):
total = total + List[ele]
#printing total value
print ("Sum of all elements in the given list",total)
output:
Sum of all elements in the given list 212
input:
#Python program to multiply elements in a list
total = 1
#creating lists
list1 = [1,5,2]
list2 = [2,3,4]
#iterate each element in list
#and add them to a variable total
#ele is the index/counter.
for ele in range (0,len(list1)):
total = total * list1[ele]
#printing total value
print ("Multiplication of all elements in the given list",total)
#List2
total = 1
for ele in range (0,len(list2)):
total = total * list2[ele]
#printing total value
print ("Multiplication of all elements in the given list",total)
output:
Multiplication of all elements in the given list 10
Multiplication of all elements in the given list 24
___________________________________________________________________________
Lesson 7
Date: 25/4/2023
Day: Tuesday
input:
count = 1
while(count < 10):
if (count ==5):
break
print(count, '\n')
count = count + 1
out put:
input:
count = 1
while(count < 10):
if (count ==5):
break
print(count, end = '\n')
count = count + 1
output:
1
2
3
4
input:
count = 1
while(count < 10):
count += 1
if (count ==5):
continue
print(count, end = '\n')
output:
2
3
4
6
7
8
9
10
input:
count = 0
while(count < 9):
count += 1
if (count ==5):
continue
print(count, end = '\n')
output:
1
2
3
4
6
7
8
9
input:
count = 0
while count < 10:
print (count, " is less than 10")
count = count + 1
else:
print(count, "is not less than 10")
output:
0 is less than 10
1 is less than 10
2 is less than 10
3 is less than 10
4 is less than 10
5 is less than 10
6 is less than 10
7 is less than 10
8 is less than 10
9 is less than 10
10 is not less than 10
input:
for letter in 'Python':
print('Current letter :', letter)
output:
Current letter : P
Current letter : y
Current letter : t
Current letter : h
Current letter : o
Current letter : n
input:
for letter in 'Gunanthra Shri':
print('Current letter :', letter)
output:
Current letter : G
Current letter : u
Current letter : n
Current letter : a
Current letter : n
Current letter : t
Current letter : h
Current letter : r
Current letter : a
Current letter :
Current letter : S
Current letter : h
Current letter : r
Current letter : i
input:
#take inputs from the user
print('Area of triangle.(Enter the values in cm)')
a=float(input('Enter base: '))
b=float(input('Enter height: '))
#calculate the area
area = 0.5*a*b
print('The are of the triangle is %0.2f' %area)
output:
Area of triangle.(Enter the values in cm)
Enter base: 12
Enter height: 13
The are of the triangle is 78.00
__________________________________________________________________________________
Lesson 8
Date: 2/5/2023
Day: Tuesday
BMI Calculator
input:
#asking for input from the user
h=float(input("Enter the height in cm:"))
w=float(input("Enter the weight in kg:"))
BMI = w/(h/100)**2
print("Your Body Mass Index is",BMI)
output:
Enter the height in cm: 164
Enter the weight in kg: 37
Your Body Mass Index is 13.756692444973233
Age calculator:
input:
#calculation of the age
#ask for input of the age
a = (int(input("Enter the current year:")))
b = (int(input("Enter the year you were born:")))
Age = a-b
print ("Your age = ", Age)
output:
Enter the current year: 2023
Enter the year you were born: 2011
Your age = 12
Multiplication tables:
input:
a = int(input('Enter a number:'))
for x in range(1,13):
print (x,'*',a,' =',x*a)
output:
Enter a number: 3
1 * 3 = 3
2 * 3 = 6
3 * 3 = 9
4 * 3 = 12
5 * 3 = 15
6 * 3 = 18
7 * 3 = 21
8 * 3 = 24
9 * 3 = 27
10 * 3 = 30
11 * 3 = 33
12 * 3 = 36
multiplication table in the while loop:
input:
exit ="N"
while exit == "N":
a=int(input('Enter a number:'))
for x in range (1,13):
print(x,'*',a,' =',x*a)
exit=input('Do you want to exit?(Y/N):')
output:
Enter a number: 1
1 * 1 = 1
2 * 1 = 2
3 * 1 = 3
4 * 1 = 4
5 * 1 = 5
6 * 1 = 6
7 * 1 = 7
8 * 1 = 8
9 * 1 = 9
10 * 1 = 10
11 * 1 = 11
12 * 1 = 12
Do you want to exit?(Y/N):N
Enter a number:2
1 * 2 = 2
2 * 2 = 4
3 * 2 = 6
4 * 2 = 8
5 * 2 = 10
6 * 2 = 12
7 * 2 = 14
8 * 2 = 16
9 * 2 = 18
10 * 2 = 20
11 * 2 = 22
12 * 2 = 24
Do you want to exit?(Y/N):N
Enter a number:3
1 * 3 = 3
2 * 3 = 6
3 * 3 = 9
4 * 3 = 12
5 * 3 = 15
6 * 3 = 18
7 * 3 = 21
8 * 3 = 24
9 * 3 = 27
10 * 3 = 30
11 * 3 = 33
12 * 3 = 36
Do you want to exit?(Y/N):N
Enter a number:4
1 * 4 = 4
2 * 4 = 8
3 * 4 = 12
4 * 4 = 16
5 * 4 = 20
6 * 4 = 24
7 * 4 = 28
8 * 4 = 32
9 * 4 = 36
10 * 4 = 40
11 * 4 = 44
12 * 4 = 48
Do you want to exit?(Y/N):N
Enter a number:5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
11 * 5 = 55
12 * 5 = 60
Do you want to exit?(Y/N):N
Enter a number:6
1 * 6 = 6
2 * 6 = 12
3 * 6 = 18
4 * 6 = 24
5 * 6 = 30
6 * 6 = 36
7 * 6 = 42
8 * 6 = 48
9 * 6 = 54
10 * 6 = 60
11 * 6 = 66
12 * 6 = 72
Do you want to exit?(Y/N):N
Enter a number:7
1 * 7 = 7
2 * 7 = 14
3 * 7 = 21
4 * 7 = 28
5 * 7 = 35
6 * 7 = 42
7 * 7 = 49
8 * 7 = 56
9 * 7 = 63
10 * 7 = 70
11 * 7 = 77
12 * 7 = 84
Do you want to exit?(Y/N):Y
___________________________________________________________________________
Lesson 9
Date:23rd May 2023
\n = New line
\t = Tab space
print ('Nivi \n loves coding.')
Nivi
loves coding.
print ('Nivi \t loves coding.')
Nivi loves coding.
*Notes - Variables cannot have any speacial characters.
- Variables cannot start with numbers.
- Variables may have '_'
For loop in lists:
digits = [0,5,10]
for i in digits:
print (i)
else :
print ('No items left.')
0
5
10
No items left.
Infinite Loop
count = 1
while(count < 10):
if (count ==5):
break
print (count,'\n')
You can only exit via keyboard : Ctrl +c
While loop
count = 1
while (count < 9):
print ('The count is:',count)
count = count + 1
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
_____________________________________________________________________________
Lesson 10
Date: 11th July 2023
n = 10
while n > 0:
n = n-1
#if n == 2:
#break
print (n)
else:
print ('Loop is finished.')
9
8
7
6
5
4
3
2
1
0
Loop is finished.
# Program to add natral numberrs from 1 to n
n = 10
i = 1
sum = 0
while i <= n:
sum = sum + i
i = i + 1 #update counter
print ('The sum is ', sum)
The sum is 55
#Print all odd numbers
print ('Print all numbers')
count = 1
while (count< 100):
print (count)
count = count + 2
Print odd numbers
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
#print all even numbers
print ('Print even numbers.')
count = 2
while (count <100):
print (count)
count = count + 2
Print even numbers.
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
#Print all nmbers in the reverse order
print ('Print in reverse order.')
count = 100
while (count >0):
print (count)
count = count - 1
Print in reverse order.
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
#add all the numbers
total = 0
x = int(input('Enter a number: '))
while x!=0:
total = total + x
x = int(input('Enter a number: '))
print ('Total = ',total)
Enter a number: 123
Enter a number: 234
Enter a number: 345
Enter a number: 456
Enter a number: 567
Enter a number: 678
Enter a number: 78
Enter a number: 789
Enter a number: 8910
Enter a number: 0
Total = 12180
____________________________________________________________________________
Lesson 11
Date:24th July 2023
#write a python program to display all numbers 1 to 10 using a while loop
n=1
while n<=10 :
print(n)
n=n+1
print ("Loop ends")
1
2
3
4
5
6
7
8
9
10
Loop ends
#write a python program to display all numbers 10 to 1 using a while loop
n=10
while n>=1 :
print(n)
n=n-1
print ("Loop ends")
10
9
8
7
6
5
4
3
2
1
Loop ends
#write a python program to display all the even numbers 1 to 10 using a
while loop
n=2
while n<=10 :
print(n)
n=n+2
print ("Loop ends")
2
4
6
8
10
Loop ends
#write a python program to display all the odd numbers 1 to 10 using a while
loop
n=1
while n<=10 :
print(n)
n=n+2
print ("Loop ends")
1
3
5
7
9
Loop ends
n=1
num = int(input('Enter a number: '))
while n<=num :
print(n)
n=n+1
print ("Loop ends")
Enter a number: 20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Loop ends
#write a python program to add all
#numbers the user enters
#using a while loop
#stop if he enters a zero
total = 0
num=1
while num !=0:
num=int(input("Enter a number: "))
total=total+num
print (total)
print ("Loop ends")
print ("Grand total is: ",total)
Enter a number: 4
4
Enter a number: 6
10
Enter a number: 2
12
Enter a number: 9
21
Enter a number: 0
21
Loop ends
Grand total is: 21
____________________________________________________________________________
Lesson 12
Date: 1st August 2023
#To find the greatest number
#To create a loop until user enters 'N'
cont_ind = 'Y'
while cont_ind == 'Y':
Number1 = int(input("Enter a number: "))
Number2 = int(input("Enter a number: "))
Number3 = int(input("Enter a number: "))
if Number1 > Number2 and Number1 > Number3:
print (Number1," is the greatest.")
elif Number2 > Number1 and Number2 > Number3:
print (Number2," is the greatest.")
else:
print (Number3," is he greatest.")
if Number1 < Number2 and Number1 <Number3:
print (Number1," is the smallest.")
elif Number2 < Number1 and Number2 < Number3:
print (Number2, "is the smallest.")
else:
print (Number3, "is the smallest.")
cont_ind =input("Do you want to continue? (Y/N)")
Enter a number: 3
Enter a number: 2
Enter a number: 1
3 is the greatest.
1 is the smallest.
Do you want to stop? (Y/N)Y
Enter a number: 3
Enter a number: 0
Enter a number: 6
6 is he greatest.
0 is the smallest.
Do you want to stop? (Y/N)N
_____________________________________________________________________________
Lesson 12
Date : 18th January 2024
def addition (num1, num2):
num3 = num1 + num2
return num3
#main program
num1 = 5
num2 = 12
ans = (num1 + num2)
print ("The answer is ",ans)
def subtraction (num1, num2):
num3 = num1 - num2
return num3
#main program
num1 = 5
num2 = 12
ans = (num1 - num2)
print ("The answer is ",ans)
def mutiplication (num1, num2):
num3 = num1 * num2
return num3
#main program
num1 = 5
num2 = 12
ans = (num1 * num2)
print ("The answer is ",ans)
def division (num1, num2):
num3 = num1 / num2
return num3
#main program
num1 = 5
num2 = 12
ans = (num1 / num2)
print ("The answer is ",ans)
The answer is 17
The answer is -7
The answer is 60
The answer is 0.4166666666666667
____________________________________________________________________________
Lesson 13
Date : 30th January 2024
#basic shape drawing
import turtle
Gunanthra = [Link]()
[Link]("Purple")
[Link](10)
[Link]("turtle")
[Link](100)
[Link](90)
[Link]()
[Link](100)
[Link](90)
[Link]()
[Link]("blue")
[Link](100)
Thahseen = [Link]()
[Link]("Black")
[Link](8)
[Link](1)
print([Link]())
[Link]([Link]()[0], [Link]()[1])
[Link](100)
#draw square
import turtle
ben = [Link]()
for i in range (4):
[Link](100)
[Link](90)
[Link]()
_____________________________________________________________________________
Lesson 13
Date: 6th Febuary 2024
#Draw polygon
import turtle
polygon=[Link]()
sides=int(input("Enter your number: "))
length=int(input("Enter your number: "))
angle=360.0/sides
for i in range(sides):
[Link](length)
[Link](angle)
[Link]()
#draw a chess board
import turtle
sc = [Link]()
pen=[Link]()
def draw() :
for i in range (4) :
[Link](30)
[Link](90)
[Link](30)
if __name__ == "__main__" :
[Link](600,600)
[Link](100)
for i in range (8):
[Link]()
[Link](0,30*i)
[Link]()
for j in range (8):
if(i+j) %2==0 :
col="black"
else:
col="white"
[Link](col)
pen.begin_fill ()
draw ()
pen.end_fill ()
[Link] ()
#Nested for loop
#Outer loop
for i in range(5):
#Inner loop
for x in range (0,5):
print ("*", end="")
print ()
_____________________________________________________________________________
Lesson 14
Date : 20th February 2024
Linear Search:
def binarySearch(array, x, low, high):
#repeat until the pointers low and high meet.
while low<=high:
mid = low + (high - low)//2 #//2 floor division
if array[mid] == x:
return mid
elif array[mid]<x:
low=mid+1
else:
high=mid-1
return -1
#main program
array = [2, 4, 5, 7, 14, 17, 19, 22]
#item to find
x=19
result=binarySearch(array,x,0,len(array)-1)
if result !=-1:
print ("Item at index:", result)
print ("Item is ",array[result])
else:
print ("Item not found")
Binary search:
def binarySearch(array, x, low, high):
#repeat until the pointers low and high meet.
while low<=high:
mid = low + (high - low)//2 #//2 floor division
if array[mid] == x:
return mid
elif array[mid]<x:
low=mid+1
else:
high=mid-1
return -1
#main program
array = [2, 4, 5, 7, 14, 17, 19, 22]
#item to find
x=19
result=binarySearch(array,x,0,len(array)-1)
if result !=-1:
print ("Item at index:", result)
print ("Item is ",array[result])
else:
print ("Item not found")
______________________________________________________________________________
Lesson 15
Date : 27th February 2024
import datetime
#x is a variable
x=[Link]()
print (x)
print ([Link]("%A"))
print ([Link]("%B"))
print ([Link]("%Y"))
print ([Link]("%y"))
x=[Link](2020, 5, 17)
print (x)
show_datetime=[Link](2024, 5, 1, 10, 0, 0)
#format date to show on screen
print (show_datetime.strftime("%H:%M:%S %B %d %Y"))
#[Link] May 01 2024
from datetime import datetime
'''
#current date and time
today=[Link]()
graduation_day=datetime(2024,8,11,0,0,0)
#finding the difference
days_left=abs(graduation_day - today)
#display the number of days
print (f"Days left till grdauation:{days_left}")
'''
first_date=datetime(2024,1,1)
second_date=datetime(2024,12,31)
date_diff=second_date-first_date
print ("Diff is ",date_diff)
#extract weekday name
weekday_format=''
for year in range (2022,2024):
print (f"Weekday of December :31,{year} is {datetime(year,12,31).strftime
(weekday_format)}.")
______________________________________________________________________________
Lesson 16
Date : 5th March 2024
from datetime import datetime, timedelta
#adding 9 hours
hour_delta = timedelta(hours=9)
#storing the new date
timeAdded = [Link]() + hour_delta
#Displaying the current datetime with 9 hours added
print (f"The date after adding 9 hours: {timeAdded}")
#adding 1 day
day_delta = timedelta(days=1)
timeAdded = [Link]() + day_delta
print (f"The date after adding 1 day is: {timeAdded}")
______________________________________________________________________________
Lesson 17
Date: 12th March 2024
program to check if the given number is a prime number or not
num=65
if num>1:
#iterate from 2 to num/2
for i in range (2, int(num/2)+1):
#if num is divisible by any other number
#then it is not a prime number
if (num%i)==0:
print (num, "is not a prime number.")
break
else:
print ("num is", num)
print ("i is", i)
else:
print (num,"is a prime number.")
_____________________________________________________________________________
Lesson 18
Date: 26th March 2024
import math
num=16
sq=[Link](num,2)
print ("Result",sq)
sqrt=[Link](num)
print ("Sq root",sqrt)
sqrt=[Link](100)
print ("Sq root",sqrt)
cubert=8**(1/3)
print ("Cube root of 8 is",cubert)
#print ("The square of 8 is:",8**2)
#print ("The cube of 8 is:",8**3)
#print ("Power to the 4 of 8 is:",8**4)
import math
num=-5.7
print ("Math Ceiling",[Link](num))
print ("Math Floor",[Link](num))
print ("Math Round",round(num))
print("Math Fabs",[Link](num))
import math
import random
num1=30
num2=20
print ("GCD",[Link](num1,num2))
print ("LCM",[Link](num1,num2))
print ("",[Link])
#Area of circle
r=7
area=round([Link]*(r**2))
print ("Area of circle",area)
num=[Link](3)
print ("num",num)
______________________________________________________________________________
Lesson 19
Date: 2nd April 2024
import math
def calc_area_circle(radius):
return [Link]*radius**2
def calc_perimeter_circle(radius):
return 2*[Link]*radius
radius = int(input("Enter the radius: "))
print (f"Area of the circle",calc_area_circle(radius))
print (f"Perimeter of the circle",calc_perimeter_circle(radius))
#Q2
import random
User_num=1
while User_num !=0:
User_num = int(input("Enter a number: "))
Comp_num = [Link](1,20)
if Comp_num == User_num:
print ("Congrats!!👌👌 Computer generated:",Comp_num)
break
else:
print ("Try again!!")
if Comp_num > User_num:
print ("Guess higher")
else:
print ("Guess lower")
______________________________________________________________________________
Lesson 20
Date : 23rd April 2024
#Roll a dice
import random
def roll_dice():
return [Link](1,6)
def play_game(player_name):
player_roll = roll_dice()
comp_roll = roll_dice()
print ('Player roll is', player_roll)
print ("Comp roll is", comp_roll)
if player_roll > comp_roll:
print (player_name,"wins.🎉")
elif player_roll < comp_roll:
print ("Computer wins.")
else:
print ("It's a tie.")
#Get player name
player_name = input("Enter your name: ")
print ("Let's paly a dice rolling game.")
play_game(player_game)
________________________________________________________________________________
Lesson 21
Date : 9th July 2024
#Student grade dictionary
student_grades = {}
def add_student(name, grade):
student_grades[name] = grade
###student_grades[grade] = grade
print (f"Added {name} with grade {grade}")
def update_grade(name,grade):
if name in student_grades:
student_grades[grade] = grade
print (f"Updated {name}'s grade to {grade}")
else:
print (f"Student {name} not found")
def display_students():
if student_grades:
for name, grade in student_grades.items():
print (f"Student:{name}, Grade: {grade}")
else:
print ("No student records found")
#Main
add_student ("Alice",85)
add_student("Bob",60)
add_student ("Charlie", 79)
print ("\n Current Students: ")
display_students()
'''In Python, a dictionary can be created by placing a sequence with a curly {}
seperated by a comma.'''
#1 - values()
users:dict = {0: 'Mario', 1: 'Luigi', 2: 'James'}
print ([Link]())
#2 - keys()
users:dict = {0: 'Mario', 1: 'Luigi', 2: 'James'}
print ([Link]())
#We can access the value of a dictionary item by placing the key inside inside
#square brackets
country_capitals={
"Germany" :"Berlin",
"Canada":"Ottawa",
"England":"London"
}
#Access the value of the keys
print (country_capitals["Germany"])
print (country_capitals["England"])
# Add an item to the dictionary
country_capitals["Italy"] = "Rome"
print (country_capitals)
# Update
country_capitals["Italy"] = "Naples"
print (country_capitals)
# loop
# Print dictionary values one by one
for i in country_capitals:
capital = country_capitals[i]
print (capital)