PYTHON PROGRAMS WORKSHEET -1 ( DECISION MAKING USING IF-ELIF-ELSE)
1. Number Classification
num = int(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
2. Check Voting Eligibility
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
3. Grade Calculation in Python
marks = int(input("Enter your marks: "))
if marks >= 90:
print("Grade: A")
elif marks >= 80:
print("Grade: B")
elif marks >= 70:
print("Grade: C")
elif marks >= 50:
print("Grade: D")
else:
print("Grade: F")
4. Check Even or Odd number
num = int(input("Enter a number: "))
if (num % 2 == 0):
print("The number is even.")
else:
print("The number is odd.")
5. Check the enter year is Leap Year or not
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
6. Find the Largest Number among 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:
print(f"The largest number is {a}.")
elif b > c and b>a:
print(f"The largest number is {b}.")
else:
print(f"The largest number is {c}.")
7. Traffic Signal light output
signal = input("Enter the traffic signal (Red/Yellow/Green): ").strip().lower()
if signal == "red":
print("Stop!")
elif signal == "yellow":
print("Get ready to move.")
elif signal == "green":
print("Go!")
else:
print("Invalid signal input.")
8. Simple Calculator in Python
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
operation = input("Choose operation (+, -, *, /): ")
if operation == "+":
print(f"Result: {a + b}")
elif operation == "-":
print(f"Result: {a - b}")
elif operation == "*":
print(f"Result: {a * b}")
elif operation == "/" and b != 0:
print(f"Result: {a / b}")
else:
print("Invalid operation or division by zero.")
9. Check the input Character Type
char = input("Enter a character: ")
if char.isalpha():
print("It is a letter.")
elif char.isdigit():
print("It is a digit.")
else:
print("It is a special character.")