0% found this document useful (0 votes)
5 views4 pages

Python Lab

Uploaded by

kanishktak07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Python Lab

Uploaded by

kanishktak07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MAHAVEER PUBLIC SCHOOL

CLASS X (AI)
Python Practical

1. Write a Python program to calculate the surface area and volume of a cuboid.

length = float(input('Enter length: '))


width = float(input('Enter width: '))
height = float(input('Enter height: '))
surface_area = 2 * (length * width + length * height + width * height)
volume = length * width * height
print('Surface area:', surface_area)
print('Volume:', volume)

Sample Input/Output:
Enter length: 20
Enter width: 14
Enter height: 10
Surface area: 1240.0
Volume: 2800.0

2. Write a Python program to ask for height in centimetres and convert it into feet and inches.

height_cm = float(input('Enter your height in centimeters: '))


height_inch = height_cm / 2.54
height_feet = height_inch // 12
remaining_inches = height_inch % 12
print('Your height is', height_feet, 'feet', remaining_inches, 'inches.')

Sample Input/Output:
Enter your height in centimeters: 162
Your height is 5.0 feet 3.7795275590551185 inches.

3. Write a Python program to calculate the area and perimeter of a rectangle.

length = float(input("Enter length of rectangle: "))


breadth = float(input("Enter breadth of rectangle: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area of rectangle:", area)
print("Perimeter of rectangle:", perimeter)
Sample Output:
Enter length of rectangle: 10
Enter breadth of rectangle: 5
Area of rectangle: 50.0
Perimeter of rectangle: 30.0

4. Write a Python program to calculate the average marks of three subjects.

m1 = float(input("Enter marks of first subject: "))


m2 = float(input("Enter marks of second subject: "))
m3 = float(input("Enter marks of third subject: "))
average = (m1 + m2 + m3) / 3
print("Average marks:", average)

Sample Output
Enter marks of first subject: 70
Enter marks of second subject: 80
Enter marks of third subject: 90
Average marks: 80.0

5. Write a Python program to check whether the applicant is eligible to vote in the elections or not.

age = int(input("Enter your age: "))


if age < 18:
print("You are not eligible to vote.")
elif age == 18:
print("This is your first time voting. Make it count!")
else:
print("You are eligible to vote.")

Sample Output:
Enter your age: 28
You are eligible to vote.
6. Write a Python program to check whether the entered number is positive and even, positive and
odd, negative and even, or negative and odd.

num = int(input("Enter a number: "))


if num > 0:
if num % 2 == 0:
print("The number is positive and even.")
else:
print("The number is positive and odd.")
elif num < 0:
if num % 2 == 0:
print("The number is negative and even.")
else:
print("The number is negative and odd.")
else:
print("The number is zero.")

Sample Output:
Enter a number: 19
The number is positive and odd.

7. Write a Python Program to find largest of three numbers.

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c
print("The largest number is:", largest)

Sample Output
Enter first number: 12
Enter second number: 45
Enter third number: 30
The largest number is: 45
8. Write a Python program to print a table of a given number. Number has to be entered by user.

n=int(input(“Enter the number:”))


for i in range(1,11):
print(n,"*",i,"=",n*i)

Sample Output:
Enter the number:5
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

9. Write a Python program to print the sum of the first 10 natural numbers.

total = 0
for i in range(1, 11):
total = total + i
print("Sum of the first 10 natural numbers is:", total)

Sample Output:
Sum of the first 10 natural numbers is: 55

10. Write a Python program to input two numbers and find HCF and LCM.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
hcf = 1
for i in range(1, a + 1):
if a % i == 0 and b % i == 0:
hcf = i
lcm = (a * b) // hcf
print("HCF =", hcf)
print("LCM =", lcm)

Sample Output:
Enter first number: 12
Enter second number: 18
HCF of 12 and 18 is: 6
LCM of 12 and 18 is: 36

You might also like