Python programs – Class IX (Part – 1)
1. Write a program to calculate total and average of a student in 5 subjects
Sol:
#program to find total and average marks of a student in 5 subjects
eng=float(input("enter english marks"))
hin=float(input("enter hindi marks"))
mat=float(input("enter maths marks"))
sci=float(input("enter science marks"))
sst=float(input("enter social marks"))
tot=eng+hin+mat+sci+sst
avg=tot/5
print("the total marks =",tot)
print("the average marks=",avg)
Output:
2. Write a program to calculate simple interest and print it
Sol:
#program to find and print the simple interest
p=float(input("enter principle "))
t=float(input("enter time"))
r=float(input("enter rate of interest"))
si=(p*t*r)/100
print("the simple interest = ",si)
Output:
3. Write a python program to print the area and perimeter of a square,
rectangle and area and circumference of a circle
Sol:
#rectangle
l=float(input("enter length of a rectangle"))
b=float(input("enter breadth of a rectangle"))
area=l*b
peri=2*(l+b)
print("the area of a rectangle =",area)
print("the perimeter of a rectangle=", peri)
#square
s=float(input("enter side of a square"))
area2=s*s
peri2=4*s
print("the area of a square =", area2)
print("the perimeter of a square =", peri2)
#circle
r=float(input("enter radius of a circle"))
pi=3.14
area3=pi*(r**2)
cir=2*pi*r
print("the area of a circle = ", area3)
print("the circumference of a circle =", cir)
Output:
4. Write a python program to find ‘profit’ or ‘loss’
Sol:
#program to find the 'profit' or 'loss'
cp=float(input("enter cost price"))
sp=float(input("enter selling price"))
if cp==sp:
print("no profit - no loss")
else:
if cp<sp:
profit=sp-cp
print("the profit is =",profit)
else:
loss=cp-sp
print("the loss is =", loss)
Output:
5. Write a python program to find the result “pass” or “fail” of a student
Sol:
#program to find total and average marks of a student in 5 subjects
eng=float(input("enter english marks"))
hin=float(input("enter hindi marks"))
mat=float(input("enter maths marks"))
sci=float(input("enter science marks"))
sst=float(input("enter social marks"))
if eng>=35 and hin>=35 and mat>=35 and sci>=35 and sst>=35:
print("the student is passed")
tot=eng+hin+mat+sci+sst
avg=tot/5
print("the total marks =",tot)
print("the average marks=",avg)
else:
print("the student is failed")
Output: