You are on page 1of 6

LIST OF PRACTICAL PROGRAMS-CLASS-IX-2023-24

P01: Program to print string into following pattern.


p
py
pyt
pyth
pytho
python

Program:
name=”python”
x=““
for i in name:
x+=i
print(x)

P02: Program to print following pattern:


*************
* *
* *
*************
Program:
print(“* * * * * * * * * * * *”)
print(“* *”)
print(“* *”)
print(“* * * * * * * * * * * *”)

P03: Program to add two numbers

Program:
num1=int(input(“Enter number1:”))
num2=int(input(“Enter number2:”))
sum=num1+num2
print(“The sum of two numbers is = “, sum)

Output:
Enter number1: 10
Enter number2: 20
The sum of two numbers is = 30

P04: Program to execute operations of a simple calculator


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

P05: Program to calculate simple interest

Program:
P=float(input(“Enter principle amount:”))
T=float(input(“Enter time:”))
R=float(input(“Enter rate of interest:”))
SI=(P*T*R)/100
print(“The simple interest is = “, SI)

Output:
Enter principle amount: 5000
Enter time: 2
Enter rate of interest: 15
The simple interest is = 1500
P06: Program to calculate area and perimeter of rectangle

Program
length = float(input("Enter length of the rectangle: "))
breadth = float(input("Enter breadth of the rectangle: "))
area = length * breadth
perimeter = 2 * (length * breadth)
print("Area of rectangle = ", area)
print("Perimeter of rectangle = ", perimeter)

Output:
Enter length of the rectangle: 23
Enter breadth of the rectangle: 17
Area of rectangle = 391.0
Perimeter of rectangle = 782.0

P07: Program to calculate area and perimeter of a circle


Program:
# Initialising the value of PI
PI = 3.14
R = float(input("Enter radius of the circle: "))
area = (PI*R*R)
perimeter = (2*PI*R)
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

P08: Program to find eligibility to vote (if else)


Program:
# input age
age = int(input("Enter Age : "))
# condition to check voting eligibility
if age >= 18:
status = "Eligible"
else:
status = "Not Eligible"
print("You are ", status, " for Vote.")

Output:
RUN 1:
Enter Age : 21
You are Eligible for Vote.
RUN 2:
Enter Age : 17
You are Not Eligible for Vote.

P09: Program to find grade of a student based on percentage of marks (if elif else)

Program:
print("Enter Marks Obtained in 5 Subjects: ")
markOne = int(input())
markTwo = int(input())
markThree = int(input())
markFour = int(input())
markFive = int(input())

tot = markOne+markTwo+markThree+markFour+markFive
avg = tot/5

if avg>=91 and avg<=100:


print("Your Grade is A1")
elif avg>=81 and avg<91:
print("Your Grade is A2")
elif avg>=71 and avg<81:
print("Your Grade is B1")
elif avg>=61 and avg<71:
print("Your Grade is B2")
elif avg>=51 and avg<61:
print("Your Grade is C1")
elif avg>=41 and avg<51:
print("Your Grade is C2")
elif avg>=33 and avg<41:
print("Your Grade is D")
elif avg>=21 and avg<33:
print("Your Grade is E1")
elif avg>=0 and avg<21:
print("Your Grade is E2")
else:
print("Invalid Input!")

output:
Enter Marks Obtained in 5 Subjects:
89
76
78
45
35
Your Grade is B2
P10: Program to print given number is even or odd.(if else)

Program:
number = int(input("Enter any number:"))
if number/2 = = 0:
print(" Entered number is even")
else:
print("Entered number is odd")

Ouput:
Enter any number: 18
Entered number is even
Enter any number: 21
Entered number is odd

P11: Program to print “Hello” n times when n is inputted by the user. (for loop)
Program:
print("How many time to Print ? ")
tot = int(input())
for i in range(tot):
print("Hello")

Output:
How many time to Print ?
5
Hello
Hello
Hello
Hello
Hello

P12: Program to print multiplication table of given number (while loop)

Program:
n = int(input("Enter any Number :"));
i=1
while i < 11:
res = n * i
print(n," * ",i," = ",res)
i=i+1
Output:
Enter any Number :13
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 117
13 * 10 = 130
P13: Program to print a number series from x to y when x and y are inputted by the
user. (for/while)

Program:
x =int(input(Enter x value:”))
y =int(input(Enter y value:”))
for num in range(x, y + 1):
print(num)

Output:
Enter x value : 5
Enter y value : 9
5
6
7
8
9

P14: Program to enter first name and last name and then display the message:
Hello FirstName LastName

Program:

fname = input("Input your First Name : ")


lname = input("Input your Last Name : ")
print("Hello " + lname + " " + fname)

Output:
Input your First Name : Venu
Input your Last Name : Gopal
Hello Venu Gopal

P15: Program to reverse the elements of list.

Program:
L1= [1,2,3,4,5,6]
print('Given sequence:', L1)
L1.reverse()
print('Reversed sequence:', L1)

Output:
Given sequence: [1,2,3,4,5,6]
Reversed sequence: [6,5,4,3,2,1]

You might also like