(Grade IX) Part 3-Conditional Programs
1.
Write
a program to input a number and check whether it is positive or negative.
num
= float(input("Enter a number: "))
if
num > 0:
print("The number is positive")
else:
print("The number is negative")
2.
Write
a program to input the age of a person and check whether they are eligible to
vote (age ≥ 18).
age
= int(input("Enter your age: "))
if
age >= 18:
print("You are eligible to vote")
else:
print("You are not eligible to
vote")
3.
Write
a program to input two numbers and print the greater number.
a
= float(input("Enter first number: "))
b
= float(input("Enter second number: "))
if
a > b:
print(a, "is greater")
else:
print(b, "is greater")
4.
Write
a program to input a number and check whether it is even or odd.
num
= int(input("Enter a number: "))
if
num % 2 == 0:
print("The number is even")
else:
print("The number is odd")
Write
a program to input a year and check whether it is a leap year or not.
year
= int(input("Enter a year: "))
if
(year % 4 == 0):
print(year, "is a leap year")
else:
print(year, "is not a leap
year")
5.
Write
a program to input a number and check whether it is zero, positive, or
negative.
num
= float(input("Enter a number: "))
if
num == 0:
print("The number is zero")
elif
num > 0:
print("The number is
positive")
else:
print("The number is
negative")
6.
Write
a program to input marks obtained by a student and print the grade:
≥
80: "A+"
60–79:
"A"
40–59:
"B"
<
40: "Fail"
marks
= float(input("Enter marks obtained: "))
if
marks >= 80:
print("Grade: A+")
elif
marks >= 60 and marks<=79:
print("Grade: A")
elif
marks >= 40 and marks<=59:
print("Grade: B")
else:
print("Grade: Fail")
7.
Write
a program to input three numbers and print the largest among them.
a
= float(input("Enter first number: "))
b
= float(input("Enter second number: "))
c
= float(input("Enter third number: "))
if
a > b and a > c:
print(a, "is the largest")
elif
b >a and b > c:
print(b, "is the largest")
else:
print(c, "is the largest")
8.
Write
a program to input the price of an item and calculate discount:
Price
> 5000: 20% discount
Price
between 2000–5000: 10% discount
Price
< 2000: no discount
price
= float(input("Enter the price of the item: "))
if
price > 5000:
discount = price * 0.20
elif
price >= 2000:
discount = price * 0.10
else:
discount = 0
final_price
= price - discount
print("Discount:",
discount)
print("Final
price after discount:", final_price)
9.
Write
a program to input three sides of a triangle and check whether they form equilateral,
isosceles, or scalene.
s1
= float(input("Enter first side: "))
s2
= float(input("Enter second side: "))
s3
= float(input("Enter third side: "))
if
s1 == s2 == s3:
print("It is a Equilateral triangle")
elif
s1 == s2 or s2 == s3 or s1 == s3:
print("The triangle is
Isosceles")
else:
print("It is a scalene triangle")