Python Project
Python Project
CODE
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area of the rectangle:", area)
print("Perimeter of the rectangle:", perimeter)
OUTPUT
Q3. Write a program to calculate BMI (Body Mass Index)
of a person. Formula is BMI = kg / m2 where kg is a
person’s weight in kilograms and m2 is their height in
metres squared.
CODE
radius = float(input("Enter the radius of the circle:"))
area = 3.14159 * radius * radius
circumference = 2 * 3.14159 * radius
print("Area of the circle:", area)
print("Circumference of the circle:", circumference)
OUTPUT
Q5. Write a program that accepts marks in 5 subjects and
outputs average marks.
OUTPUT
Q8. Write a program to find the simple interest. Simple
Interest = (P x T x R)/100
CODE
P = float(input("Enter the Principal amount: "))
T = float(input("Enter the Time (in years): "))
R = float(input("Enter the Rate of Interest (per annum): "))
SI = (P * T * R) / 100
print(f"Simple Interest: {SI}")
OUTPUT
Q9. Write a program to find the compound interest.
Compound Interest = P(1 + R/100)T
CODE
P = float(input("Enter the Principal amount: "))
R = float(input("Enter the Rate of Interest (per annum): "))
T = float(input("Enter the Time (in years): "))
A = P * (1 + R / 100) ** T
CI = A - P
print(f"Compound Interest: {CI}")
print(f"Total Amount after {T} years: {A}")
OUTPUT
Q10. Write a program that generates the following output :
5
10
9
Assign value 5 to a variable using assignment operator (=).
Multiply it with 2 to generate 10 and subtract 1 to generate
9.
CODE
num = 5
print(num)
num = num * 2
print(num)
num = num - 1
print(num)
OUTPUT
Q11. Write a program to input distance between two cities
(in kms) through the keyboard and convert and the distance
in meters and centimeters and print onto the screen
CODE
distance_km = float(input("Enter the distance between
two cities (in km): "))
distance_m = distance_km * 1000
distance_cm = distance_km * 100000
print(f"Distance in meters: {distance_m} m")
print(f"Distance in centimeters: {distance_cm} cm")
OUTPUT
Q12. Write a program to input the marks obtained by a
student in five subject. Find out the aggregate marks and
percentage marks obtained by the student.
CODE
subject1 = float(input("Enter marks for Subject 1: "))
subject2 = float(input("Enter marks for Subject 2: "))
subject3 = float(input("Enter marks for Subject 3: "))
subject4 = float(input("Enter marks for Subject 4: "))
subject5 = float(input("Enter marks for Subject 5: "))
aggregate_marks = subject1 + subject2 + subject3 + subject4 +
subject5
total_marks_per_subject = float(input("Enter the total marks
for each subject: "))
total_marks = total_marks_per_subject * 5
percentage = (aggregate_marks / total_marks) * 100
print(f"Aggregate Marks: {aggregate_marks}")
print(f"Percentage: {percentage:.2f}%")
OUTPUT
Q13. Write a program to input the temperature of a city in
Fahrenheit degrees and convert it into Centigrade degrees.
CODE
fahrenheit = float(input("Enter the temperature in
Fahrenheit: "))
celsius = (fahrenheit - 32) * 5 / 9
print(f"Temperature in Celsius: {celsius:.2f}°C")
OUTPUT
Q14. Write a program to input two numbers through
keyboard and interchange the numbers using third variable.
CODE
a = float(input("Enter the first number (a): "))
b = float(input("Enter the second number (b): "))
temp = a
a = b
b = temp
print(f"After swapping: a = {a}, b = {b}")
OUTPUT
Q15. Write a program to input two numbers through
keyboard and interchange the numbers without using third
variable.
CODE
a = float(input("Enter the first number (a): "))
b = float(input("Enter the second number (b): "))
a = a + b
b = a - b
a = a - b
print(f"After swapping: a = {a}, b = {b}")
OUTPUT
Q16. Write a program to find the cost price of an item. Take
input the total selling price of 15 items and the total profit
earned.
CODE
total_selling_price = float(input("Enter the total selling
price of 15 items: "))
total_profit = float(input("Enter the total profit earned: "))
total_cost_price = total_selling_price - total_profit
cost_price_per_item = total_cost_price / 15
print(f"Total Cost Price of 15 items: {total_cost_price}")
print(f"Cost Price of one item: {cost_price_per_item}")
OUTPUT
Q17. Write a program to calculate energy using this formula:
energy = mgh
CODE
m = float(input("Enter the mass (kg): "))
h = float(input("Enter the height (m): "))
g = 9.81
energy = m * g * h
print(f"Energy (Joules): {energy}")
OUTPUT
Q18. Write a program to calculate distance using this
formula: distance = ut+1/2at2
CODE
u = float(input("Enter the initial velocity (u in m/s): "))
a = float(input("Enter the acceleration (a in m/s²): "))
t = float(input("Enter the time (t in seconds): "))
distance = u * t + (1 / 2) * a * t ** 2
print(f"Distance traveled: {distance} meters")
OUTPUT
Q19. Write a program to input two numbers and print the
largest of the two using if statement.
CODE
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if num1 > num2:
largest = num1
else:
largest = num2
print(f"The largest number is: {largest}")
OUTPUT
Q20. Write a program to input three numbers and print the
largest of the three using if statement
CODE
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
if num1 >= num2 and num1 >= num3:
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print(f"The largest number is: {largest}")
OUTPUT
Q21. Write a program to input any number and find out
whether number is even or odd using only if statement.
CODE
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is an even number.")
else:
print(f"{num} is an odd number.")
OUPUT
Q22. Write a program to input any number and find out
whether number is positive or negative using only if
statement.
CODE
num = float(input("Enter a number: "))
if num > 0:
print(f"{num} is a positive number.")
elif num < 0:
print(f"{num} is a negative number.")
else:
print("The number is zero.")
OUTPUT
Q23. Write a program to input two numbers and find the
smallest number using if-else statement.
CODE
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if num1 < num2:
smallest = num1
else:
smallest = num2
print(f"The smallest number is: {smallest}")
OUTPUT
Q24. Write a program to input two numbers and print the
largest of the two using if-else statement.
CODE
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if num1 > num2:
largest = num1
else:
largest = num2
print(f"The largest number is: {largest}")
OUTPUT
Q25. Write a program to input a number and check whether
the entered number is positive, negative or zero using if-elif-
else statement
CODE
num = float(input("Enter a number: "))
if num > 0:
print(f"{num} is a positive number.")
elif num < 0:
print(f"{num} is a negative number.")
else:
print("The number is zero.")
OUTPUT
Q26. Write a program to input two numbers and test the
divisibility of first number with second number.
CODE
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if num2 != 0:
if num1 % num2 == 0:
print(f"{num1} is divisible by {num2}.")
else:
print(f"{num1} is not divisible by {num2}.")
else:
print("Error: Division by zero is not allowed.")
OUTPUT
Q27. Write a program to display a menu for calculating area
of a circle or perimeter of a circle.
CODE
pi=3.14
print("Menu:")
print("1. Calculate the area of circle:")
print("2. Calculate the perimeter:")
print("3. Exit:")
while True:
choice = input("Enter your choice (1/2/3):")
if choice== '1':
radius = float(input("Enter the radius of circle:"))
area =pi*radius**2
print("Area of circle is:",area)
elif choice=='2':
radius = float(input("Enter the radius of circle:"))
perimeter= 2*pi*radius
print("Perimeter of circle:",perimeter)
else:
print("Inalid choice.Please select he correct option")
OUTPUT
Q.28 Write a program to calculate the total expenses.
Quantity and price per item are input by the user and
discount of 10% is offered if the expense is more than 5000.
CODE
quantity = int(input("Enter the quantity of items: "))
price_per_item = float(input("Enter the price per item: "))
OUTPUT
Q29. Write a program to check whether a triangle is valid
or not, when the three angles of the triangle are entered by
the user. A triangle is valid if the sum of all the three
angles is equal to 180 degrees.
CODE
angle1 = int(input("Enter the first angle: "))
angle2 = int(input("Enter the second angle: "))
angle3 = int(input("Enter the third angle: "))
if angle1 + angle2 + angle3 == 180:
print("The triangle is valid.")
else:
print("The triangle is not valid.")
OUTPUT
Q30. Write a program to determine whether the year is a
leap year or not.
CODE
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100!= 0) or (year % 400 == 0):
print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
OUTPUT
Q31. The marks obtained by a student in 5 different subjects
are input by the user. The student gets a division as per the
following rules:
Percentage above or equal to 60 - First division
Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division
Percentage less than 40 – Fail
Write a program to calculate the division obtained by the
student.
CODE
subject1 = float(input("Enter marks for Subject 1: "))
subject2 = float(input("Enter marks for Subject 2: "))
subject3 = float(input("Enter marks for Subject 3: "))
subject4 = float(input("Enter marks for Subject 4: "))
subject5 = float(input("Enter marks for Subject 5: "))
total_marks = subject1 + subject2 + subject3 + subject4 + subject5
percentage = (total_marks / 500) * 100
if percentage >= 60:
print("First Division")
elif 50 <= percentage < 60:
print("Second Division")
elif 40 <= percentage < 50:
print("Third Division")
else:
print("Fail")
OUTPUT
CODE
for num in range(1, 11):
print(num)
OUTPUT
Q33. Write a program to print value even numbers from 1 to
10 using for loop
CODE
OUTPUT
Q34. Write a program to print table of any number using for
loop.
CODE
num = int(input("Enter a number: "))
print(f"Multiplication Table of {num}:")
for num in range(1, 11):
print(f"{num} × {i} = {num * i}")
OUTPUT
Q35. Write a program to print sum of first 10 natural
numbers from 1 to 10 using for loop.
CODE
sum_natural = 0
for i in range(1, 11):
sum_natural += i
print("The sum of the first 10 natural numbers is:",
sum_natural)
OUTPUT
Q36. Write a program to print value from 1 to 10 using while
loop
CODE
num = 1
while num <= 10:
print(num)
num += 1
OUTPUT
Q37. Write a program to print even nos. from 1 to 10 using
while loop.
CODE
num = 2
while num <= 10:
print(num)
num += 2
OUTPUT
Q38. Write a program to print value from 10 to 1 using while
loop.
CODE
num = 10
while num >= 1:
print(num)
num -= 1
OUTPUT
Q39. Write a program to print value even numbers from 10
to 1 using while loop
CODE
num = 10
while num >= 2:
print(num)
num -= 2
OUTPUT
Q40. Write a program to display the series using for loop /
while loop.
A. 1 3 5 7 9 :
B. 8 6 4 2 0
C. 1 4 9 16 25
D. 10 100 1000 10000
E. 3 6 9 12 15
F. -9 -7 -5 -3 -2 -1 1 3 5 7 9
A. print("Series a:")
for num in range(1, 10, 2):
print(num, end=" ")
print("\n")
OUTPUT:
B. print("Series b:")
num = 8
while num >= 0:
print(num, end=" ")
num -= 2
print("\n")
OUTPUT:
C. print("Series c:")
for num in range(1, 6):
print(num ** 2, end=" ")
print("\n")
OUTPUT:
D. print("Series d:")
num = 10
while num <= 10000:
print(num, end=" ")
num *= 10
print("\n")
OUTPUT:
E. print("Series e:")
OUTPUT:
F. print("Series f:")
num = -9
while num <= 9:
print(num, end=" ")
if num == -3:
num += 1
else:
num += 2
print()
OUTPUT:
BIBLIOGRAPHY
www.google.com
www.chatgpt.com