Professional Documents
Culture Documents
PRACTICAL: - 1
Aim: - Write a Python program to print the system date time.
import datetime
now=datetime.datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))
Output:
PRACTICAL: - 2
Aim: - Write a Python program to find sum and product of two numbers.
sum=float(num1)+float(num2)
print(num1,"+",num2,"= ",sum)
Output:
PRACTICAL: - 3
Aim: - Write a Python program which accept input from the user and perform following
operations: i) Addition ii) Subtraction iii) Multiplication iv) Division
if ch=='+':
ans=int(num1)+int(num2)
print(num1,"+",num2,"= ",ans)
elif ch=='-':
ans=int(num1)-int(num2)
print(num1,"-",num2,"= ",ans)
elif ch=='*':
ans=int(num1)*int(num2)
print(num1,"*",num2,"= ",ans)
elif ch=="/":
ans=int(num1)/int(num2)
print(num1,"/",num2,"= ",ans)
else :
Output:
PRACTICAL: - 4
Aim: - Develop programs to understand the control structures of python.
Sequential Control
print("Python Programming")
Output:
Selection Control
if var<10 :
else :
Output:
Iterative Control
print("character is ",letter)
if digit>25 :
else :
count=1
print("----While loop----")
while count<=5 :
print(count)
count=count+1
Output:
PRACTICAL: - 5
Aim: - Develop programs to learn different types of structures (list, dictionary, and
tuples) in python.
List
list1=[10,20.5,'Hello',50]
list2=[[10,20],[30,40]]
print(num)
Output:
Tuples
subjects=("Python","AI","Project")
tuple1=((10,2.5),(3.5,40))
num=()
Output:
Directory
temp = {}
temp['sun']=30.4
temp['mon']=32.2
temp['tue']=31.4
mail_id={'Monty':'monty99shah@gmail.com','Coco':'coco77@gmail.com','Daizy':'daizy1
29@gmail.com'}
dict()
num={1:'one',2:'two',3:'three'}
Output
PRACTICAL: - 6
Aim: - Develop programs to learn concept of functions scoping, recursion and list
mutability.
functions scoping
b=15
def outer() :
c=4
def inside() :
a=5
print("a : ",a)
inside()
print("c :",c)
outer()
Output
Recursion
def fact(n) :
if n==1 :
return 1
else :
return n*fact(n-1)
Output
List mutability
list1=[10,20.5,'Hello',50]
list2=[[10,20],[30,40]]
print(num)
Output:
PRACTICAL: - 7
Aim: - Develop programs to understand working of exception handling and assertions.
import math
try :
result=math.factorial(num)
print(result)
except :
Output:
Assertion
age=-21
Output: