0% found this document useful (0 votes)
46 views

Python Half Yearly Practical 2022-23

The document provides 10 programming problems to practice Python concepts for a practical exam. The problems cover topics like arithmetic operators, maximum of two numbers, area and perimeter of a circle, simple interest calculation, pattern printing, and a basic calculator. Students are required to write code for the problems and prepare a practical file and notebook submissions for evaluation.

Uploaded by

bhawna Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Python Half Yearly Practical 2022-23

The document provides 10 programming problems to practice Python concepts for a practical exam. The problems cover topics like arithmetic operators, maximum of two numbers, area and perimeter of a circle, simple interest calculation, pattern printing, and a basic calculator. Students are required to write code for the problems and prepare a practical file and notebook submissions for evaluation.

Uploaded by

bhawna Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Half Yearly Practical Programs 2022-23

TOPIC- PYTHON (50 marks)


Kindly note:

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)

Viva- 10 marks (Introduction to AI and AI Project Cycle)

Notebooks submission- 10 marks

1. Python program to find the maximum of two numbers.

a=2
b=4

maximum = max(a, b)

print(maximum)

2. Write a Python program to calculate the perimeter of a circle.

diameter = 5
perimeter = 2 * pi * diameter
print (diameter)

3. Input two integer numbers from the user and find their sum/addition in Python.

# input two numbers: value of a and b

a = int(input("Enter A: "))

b = int(input("Enter B: "))

# find sum of a and b and assign to c

c = a+b

# print sum (c)

print("Sum: ",c)

Output

Enter A: 100

Enter B: 200

Sum: 300
4. Printing different types of variables

# variable with integer value

a=12

# variable with float value

b=12.56

# variable with string value

c="Hello"

# variable with Boolean value

d=True

# printing all variables

print(a)

print(b)

print(c)

print(d)

Output

12

12.56

Hello

True

5. Python program to demonstrate the example for arithmetic operators

# Python program to demonstrate the

# example of arithmetic operators

a = 10

b=3

# addition

result = a+b

print("a+b :", result)


# subtraction

result = a-b

print("a-b :", result)

# division

result = a/b

print("a/b :", result)

# modulus

result = a%b

print("a%b :", result)

# exponent

result = a**b

print("a**b :", result)

# floor division

result = a//b

print("a//b :", result)

# updating the values of a & b

a = -10

b=3

print("a:", a, "b:", b)

result = a//b

print("a//b :", result)

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

6. Program to find the maximum of two numbers using max() method

# Python program to return maximum of two numbers

# Getting input from user

num1 = int(input("Enter the num1: "))

num2 = int(input("Enter the num2: "))

# printing the maximum value

maxVal = max(num1, num2)

print("The maximum of all values is", maxVal)

Output:

RUN 1:

Enter the num1: 12

Enter the num2: 34

The maximum of all values is 34

RUN 2:

Enter the num1: 34

Enter the num2: 12

The maximum of all values is 34

RUN 3:

Enter the num1: 12

Enter the num2: 12

The maximum of all values is 12

7. Program to find area and perimeter of a circle

# Python program to find the

# area and perimeter of circle in python

# Initialising the value of PI

PI = 3.14
# Getting input from user

R = float(input("Enter radius of the circle: "))

# Finding the area and perimeter of the circle

area = (PI*R*R)

perimeter = (2*PI*R)

# Printing the area and perimeter of the circle

print("The area of circle is", area)

print("The perimeter of circle is", perimeter)

Output:

RUN 1:

Enter radius of the circle: 1.2

The area of circle is 4.521599999999999

The perimeter of circle is 7.536

RUN 2:

Enter radius of the circle: 35.63

The area of circle is 3986.2202660000007

The perimeter of circle is 223.7564

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

Value of π = 3.14, R is the radius of a circle.

Perimeter of Circle: Also known as the circumference. It is given by the formula,

Perimeter = 2*π*R

Value of π = 3.14, R is the radius of a circle.

8. Python program to find simple interest


# Python program to find simple interest

p = float(input("Enter the principle amount : "))

r = float(input("Enter the rate of interest : "))

t = float(input("Enter the time in the years: "))

# calculating simple interest

si = (p*r*t)/100

# printing the values

print("Principle amount: ", p)

print("Interest rate : ", r)

print("Time in years : ", t)

print("Simple Interest : ", si)

Output

First run:

Enter the principle amount : 10000

Enter the rate of interest : 3.5

Enter the time in the years: 1

Principle amount: 10000.0

Interest rate : 3.5

Time in years : 1.0

Simple Interest : 350.0

Second run:

Enter the principle amount : 250000

Enter the rate of interest : 36

Enter the time in the years: 1

Principle amount: 250000.0

Interest rate : 36.0

Time in years : 1.0

Simple Interest : 90000.0


9. Python pattern printing programs

Pattern 1:

* *

* * *

* * * *

* * * * *

Code:

for row in range (0,5):

for column in range (0, row+1):

print ("*", end="")

# ending row

print('\r')

10. Design a simple calculator using if elif


Program:

# menus

print("Calculator")

print("1.Add")

print("2.Substract")

print("3.Multiply")

print("4.Divide")

# input choice

ch=int(input("Enter Choice(1-4): "))

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

You might also like