Python Half Yearly Practical 2022-23
Python Half Yearly Practical 2022-23
Practical exam- 20 marks (Kindly prepare the following programs for practical exam)
Practical file- 10 marks (Kindly prepare practical file as per the below given programs.
All students are required to run the code on any compiler and prepare file accordingly)
a=2
b=4
maximum = max(a, b)
print(maximum)
diameter = 5
perimeter = 2 * pi * diameter
print (diameter)
3. Input two integer numbers from the user and find their sum/addition in Python.
a = int(input("Enter A: "))
b = int(input("Enter B: "))
c = a+b
print("Sum: ",c)
Output
Enter A: 100
Enter B: 200
Sum: 300
4. Printing different types of variables
a=12
b=12.56
c="Hello"
d=True
print(a)
print(b)
print(c)
print(d)
Output
12
12.56
Hello
True
a = 10
b=3
# addition
result = a+b
result = a-b
# division
result = a/b
# modulus
result = a%b
# exponent
result = a**b
# floor division
result = a//b
a = -10
b=3
print("a:", a, "b:", b)
result = a//b
Output:
a+b : 13
a-b : 7
a/b : 3.3333333333333335
a%b : 1
a**b : 1000
a//b : 3
a: -10 b: 3
a//b : -4
Output:
RUN 1:
RUN 2:
RUN 3:
PI = 3.14
# Getting input from user
area = (PI*R*R)
perimeter = (2*PI*R)
Output:
RUN 1:
RUN 2:
Explanation:
In the above code, we have initialized the value of PI with 3.14. Then asked the user
for an input for the value of R. Using the formulas, we calculated the value of area and
perimeter and printed it.
We can also get the value of PI using the built-in value in Python's math library.
Area of Circle: It is the area occupied by the circle. Given by the formula,
Area = π*R*R
Perimeter = 2*π*R
si = (p*r*t)/100
Output
First run:
Second run:
Pattern 1:
* *
* * *
* * * *
* * * * *
Code:
# ending row
print('\r')
# menus
print("Calculator")
print("1.Add")
print("2.Substract")
print("3.Multiply")
print("4.Divide")
# input choice
if ch==1:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a+b
print("Sum = ",c)
elif ch==2:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a-b
print("Difference = ",c)
elif ch==3:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a*b
print("Product = ",c)
elif ch==4:
a=int(input("Enter A:"))
b=int(input("Enter B:"))
c=a/b
print("Quotient = ",c)
else:
print("Invalid Choice")
Output
Calculator
1.Add
2.Substract
3.Multiply
4.Divide
Enter Choice(1-4): 3
Enter A:10
Enter B:20
Product = 200