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

Python Practical Question

Uploaded by

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

Python Practical Question

Uploaded by

Nilkant Gorle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Practical Question

1. Display “MSBTE” using Script Mode


print("MSBTE")

2. Find the square root of a number


import math
num = float(input("Enter a number: "))
sqrt = math.sqrt(num)
print("Square root:", sqrt)

3. Convert bits to Megabytes, Gigabytes and Terabytes


bits = float(input("Enter number of bits: "))
megabytes = bits / (8 * 1024 * 1024)
gigabytes = bits / (8 * 1024 * 1024 * 1024)
terabytes = bits / (8 * 1024 * 1024 * 1024 * 1024)
print(f"{megabytes:.6f} MB, {gigabytes:.6f} GB, {terabytes:.6f} TB")

4. Swap the value of two variables


a = input("Enter first value: ")
b = input("Enter second value: ")
a, b = b, a
print("After swapping: a =", a, ", b =", b)

5. Calculate surface volume and area of a cylinder


import math
r = float(input("Enter radius: "))
h = float(input("Enter height: "))
volume = math.pi * r**2 * h
surface_area = 2 * math.pi * r * (r + h)
print("Volume:", volume)
print("Surface Area:", surface_area)

6. Calculate area and perimeter of rectangle


l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
area = l * b
perimeter = 2 * (l + b)
print("Area:", area)
print("Perimeter:", perimeter)

7. Calculate area and perimeter of square


side = float(input("Enter side length: "))
area = side * side
perimeter = 4 * side
print("Area:", area)
print("Perimeter:", perimeter)

8. Calculate area of triangle


base = float(input("Enter base: "))
height = float(input("Enter height: "))
area = 0.5 * base * height
print("Area of triangle:", area)
9. Convert Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)

10. Convert Fahrenheit to Celsius

fahrenheit = float(input("Enter temperature in Fahrenheit: "))


celsius = (fahrenheit - 32) * 5/9
print("Temperature in Celsius:", celsius)

11. Convert minutes into seconds and hours


minutes = float(input("Enter minutes: "))
seconds = minutes * 60
hours = minutes / 60
print("Seconds:", seconds)
print("Hours:", hours)

12. Find simple interest and compound interest


p = float(input("Enter principal: "))
r = float(input("Enter rate: "))
t = float(input("Enter time: "))
si = (p * r * t) / 100
ci = p * ((1 + r/100)**t) - p
print("Simple Interest:", si)
print("Compound Interest:", ci)
13. Find area of circle

import math
r = float(input("Enter radius: "))
area = math.pi * r**2
print("Area of Circle:", area)
14. Find circumference of circle
import math
r = float(input("Enter radius: "))
circumference = 2 * math.pi * r
print("Circumference:", circumference)
15. Convert kilometers into meters and centimeters
km = float(input("Enter distance in kilometers: "))
meters = km * 1000
cm = km * 100000
print("Meters:", meters)
print("Centimeters:", cm)
16. Convert days into years and weeks
days = int(input("Enter number of days: "))
years = days // 365
weeks = (days % 365) // 7
print("Years:", years)
print("Weeks:", weeks)
17. Find ASCII value of character
ch = input("Enter a character: ")
print("ASCII value of", ch, "is", ord(ch))
18. Find maximum of three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
print("Maximum number is:", max(a, b, c))

19. Calculate total, percentage and grade of marks


marks = []
for i in range(5):
marks.append(float(input(f"Enter marks for subject {i+1}: ")))
total = sum(marks)
percentage = total / 5
if percentage >= 90:
grade = 'A+'
elif percentage >= 75:
grade = 'A'
elif percentage >= 60:
grade = 'B'
elif percentage >= 50:
grade = 'C'
else:
grade = 'Fail'
print(f"Total: {total}, Percentage: {percentage:.2f}%, Grade: {grade}")
20. Check if a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")

21. Check whether a number is positive, negative or zero


python
CopyEdit
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")

22. Check whether a number is divisible by 5 and 11


python
CopyEdit
num = int(input("Enter a number: "))
if num % 5 == 0 and num % 11 == 0:
print("Divisible by 5 and 11")
else:
print("Not divisible by 5 and 11")

23. Check whether a character is alphabet or not


python
CopyEdit
ch = input("Enter a character: ")
if ch.isalpha():
print("Alphabet")
else:
print("Not an alphabet")

24. Check whether a character is vowel or consonant


python
CopyEdit
ch = input("Enter a character: ").lower()
if ch in 'aeiou':
print("Vowel")
elif ch.isalpha():
print("Consonant")
else:
print("Not a valid alphabet")

25. Check whether a character is uppercase or lowercase


python
CopyEdit
ch = input("Enter a character: ")
if ch.isupper():
print("Uppercase")
elif ch.islower():
print("Lowercase")
else:
print("Not a valid alphabet character")

26. Check whether a character is digit or not


python
CopyEdit
ch = input("Enter a character: ")
if ch.isdigit():
print("Digit")
else:
print("Not a digit")

27. Check whether a year is a leap year or not


python
CopyEdit
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")

28. Input week number and print day of week


python
CopyEdit
week_num = int(input("Enter week number (1-7): "))
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
if 1 <= week_num <= 7:
print("Day:", days[week_num - 1])
else:
print("Invalid week number")

29. Input month number and print number of days


python
CopyEdit
month = int(input("Enter month number (1-12): "))
if month == 2:
print("28 or 29 days")
elif month in [4, 6, 9, 11]:
print("30 days")
elif month in [1, 3, 5, 7, 8, 10, 12]:
print("31 days")
else:
print("Invalid month number")

30. Count number of digits in a number


python
CopyEdit
num = input("Enter a number: ")
print("Number of digits:", len(num))

You might also like