[PYTHON PROGRAMMING (2180711)]
Enrollment No. 151230107007
PRACTICAL: - 1 Aim: - Write a Python program to print the system date time.
import datetime now=datetime.datetime.now() print("Current date and Time : ") print(now.strftime("%Y-%m-%d %H:%M:%S"))
Output:
SSAIET, Computer Dept, Navsari
Page 1
[PYTHON PROGRAMMING (2180711)]
Enrollment No. 151230107007
PRACTICAL: - 2 Aim: - Write a Python program to find sum and product of two numbers.
num1=input("Enter 1st number : ") num2=input("Enter 2nd number : ") sum=float(num1)+float(num2) print(num1,"+",num2,"= ",sum)
Output:
SSAIET, Computer Dept, Navsari
Page 2
[PYTHON PROGRAMMING (2180711)]
Enrollment No. 151230107007
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
num1=input("Enter 1st number : ") num2=input("Enter 2nd number : ") ch=input("Enter operator(+,-,*,/) : ")
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 : print("Please enter above mentioned operations..")
SSAIET, Computer Dept, Navsari
Page 3
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Output:
SSAIET, Computer Dept, Navsari
Page 4
[PYTHON PROGRAMMING (2180711)]
Enrollment No. 151230107007
PRACTICAL: - 4 Aim: - Develop programs to understand the control structures of python.
Sequential Control print("S.S. Agrawal Institute of Engineering and Technology") print("Computer Engineering Department") print("Python Programming")
Output:
Selection Control
var=int(input("Enter an Integer Number : ")) if var<10 : print("Value is Less than 10.") else : print("Value is Greater than 10.")
SSAIET, Computer Dept, Navsari
Page 5
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Output:
Iterative Control
print("----for loop with string----") for letter in "python": print("character is ",letter)
print("----for loop with digit ----") for digit in[10,20,30,40]: if digit>25 : print(digit,"Greater than 25") else : print(digit,"Less than 25")
count=1 print("----While loop----") while count<=5 : print(count) count=count+1
SSAIET, Computer Dept, Navsari
Page 6
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Output:
SSAIET, Computer Dept, Navsari
Page 7
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
PRACTICAL: - 5 Aim: - Develop programs to learn different types of structures (list, dictionary, and tuples) in python.
List subjects = ["Python",8.9,"AI",9.2,"Petroleum ERP",9.8] list1=[10,20.5,'Hello',50]
list2=[[10,20],[30,40]]
for num in[10,20,30,40] : print(num)
Output:
SSAIET, Computer Dept, Navsari
Page 8
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
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':'
[email protected]','Coco':'
[email protected]','Daizy':'daizy1
[email protected]'}
dict() num={1:'one',2:'two',3:'three'}
SSAIET, Computer Dept, Navsari
Page 9
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Output
SSAIET, Computer Dept, Navsari
Page 10
[PYTHON PROGRAMMING (2180711)]
Enrollment No. 151230107007
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) print("inside the function b : ",b) inside() print("c :",c) outer()
Output
SSAIET, Computer Dept, Navsari
Page 11
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Recursion def fact(n) : if n==1 : return 1 else : return n*fact(n-1)
Output
List mutability
subjects = ["Python",8.9,"AI",9.2,"Petroleum ERP",9.8] list1=[10,20.5,'Hello',50] list2=[[10,20],[30,40]] for num in[10,20,30,40] : print(num)
SSAIET, Computer Dept, Navsari
Page 12
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Output:
SSAIET, Computer Dept, Navsari
Page 13
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
PRACTICAL: - 7 Aim: - Develop programs to understand working of exception handling and assertions.
import math num=int(input("please enter the number to calculate the factorial of : ")) try : result=math.factorial(num) print(result) except : print("cannot compute the factorial of negative numbers")
Output:
SSAIET, Computer Dept, Navsari
Page 14
Enrollment No. 151230107007
[PYTHON PROGRAMMING (2180711)]
Assertion
age=-21 assert age>=0," how is your age negative ? \n " print("Your age is : ",age)
Output:
SSAIET, Computer Dept, Navsari
Page 15