1 .
Write a program to take input a number from the user and check the number is
“Even” or “Odd”.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
2. Write a program to find the smallest of two numbers input by the user
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a < b:
print("Smallest number is", a)
elif b < a:
print("Smallest number is", b)
3. Write a program to check whether a number is divisible by 11.
num = int(input("Enter a number: "))
if num % 11 == 0:
print(num, "is divisible by 11")
else:
print(num, "is not divisible by 11")
4. Write a program to check whether a number is divisible by two, five or 7.
num = int(input("Enter a number: "))
if num % 2 == 0 or num % 5 == 0 or num % 7 == 0:
print(num, "is divisible by 2, 5, or 7")
else:
print(num, "is not divisible by 2, 5, or 7")
5. Write a program to check whether the 2 numbers input by the user are equal or print the
greater number.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a == b:
print("Both numbers are equal")
elif a > b:
print("Greater number is", a)
else:
print("Greater number is", b)
6. Write a program to print the largest of 3 numbers input by the user.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest number is", a)
elif b >= a and b >= c:
print("Largest number is", b)
else:
print("Largest number is", c)
7. Input the current temperature of the room from the user. Compare it with highest
temperature which is 51.2°C and lowest temperature which is 15.8°C for a city .Write a
program which displays that the current temperature recorded falls between highest and
lowest temperature or not.
current_temp = float(input("Enter current temperature: "))
highest = 51.2
lowest = 15.8
if lowest <= current_temp <= highest:
print("Current temperature falls between highest and lowest temperature.")
else:
print("Current temperature does not fall between highest and lowest temperature.")
8. . During a sale discounts are offered in accordance with the purchases made. Write a
program to calculate and print the discount earned and Net amount payable by the
customer after applying the discount
Purchases (P) Discount (D)
P>=10000 25% of the purchases
P>=8000 and P<10000 20% of the purchases
P>=5000 and P<8000 15% of the purchases
P<5000 5% of the purchases
purchases = float(input("Enter purchase amount: "))
if purchases >= 10000:
discount = 0.25 * purchases
elif purchases >= 8000:
discount = 0.20 * purchases
elif purchases >= 5000:
discount = 0.15 * purchases
else:
discount = 0.05 * purchases
net_amount = purchases - discount
print("Discount earned:", discount)
print("Net amount payable:", net_amount)
9. Write a program to print the Grades of the students on the basis of the marks he obtains.
Marks Grades
M>=75 A
M>=60 and M<75 B
M>=50 and M<60 C
M>=40and M<50 D
M<40 E
marks = float(input("Enter marks: "))
if marks >= 75:
grade = "A"
elif marks >= 60:
grade = "B"
elif marks >= 50:
grade = "C"
elif marks >= 40:
grade = "D"
else:
grade = "E"
print("Grade:", grade)
10. Write a Python program that takes weight (in kg) and height (in
meters) as inputs, calculates BMI, and prints the BMI category
BMI=Weight / (height 2)
BMI Range Category
Below 18.5 Under weight
18.5 to 24.9 Normal weight
25 to 29.9 Over weight
30 and above Obese
weight = float(input("Enter weight in kg: "))
height = float(input("Enter height in meters: "))
bmi = weight / (height ** 2)
print("BMI:", round(bmi, 2))
if bmi < 18.5:
print("Category: Under weight")
elif bmi <= 24.9:
print("Category: Normal weight")
elif bmi <= 29.9:
print("Category: Over weight")
else:
print("Category: Obese")
11. Write a program to check whether an entered ASCII code represents a digit, a
lower case character, Upper case character or a special character.
ASCII Range Character
48 – 57 Digits
65 – 90 Upper Case Character
97 – 122 Lower Case Character
Else Special Character
ascii_code = int(input("Enter ASCII code: "))
if 48 <= ascii_code <= 57:
print("Digit")
elif 65 <= ascii_code <= 90:
print("Upper Case Character")
elif 97 <= ascii_code <= 122:
print("Lower Case Character")
else:
print("Special Character")
12. Write a menu –driven program to find the area of a triangle and a rectangle
print("Menu")
print("1. Area of Triangle")
print("2. Area of Rectangle")
choice = int(input("Enter your choice: "))
if choice == 1:
base = float(input("Enter base of triangle: "))
height = float(input("Enter height of triangle: "))
area = 0.5 * base * height
print("Area of Triangle =", area)
elif choice == 2:
length = float(input("Enter length of rectangle: "))
breadth = float(input("Enter breadth of rectangle: "))
area = length * breadth
print("Area of Rectangle =", area)
else:
print("Invalid choice")
13 Input a number from the user and print whether it is Leap Year or not
(A year is a leap year if it is divisible by 4 and not by 100, or if it is divisible by 400.)
year = int(input("Enter a year: "))
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")