The document contains a worksheet with Python programs that demonstrate decision-making using if-elif-else statements. It includes examples for number classification, voting eligibility, grade calculation, checking even or odd numbers, determining leap years, finding the largest number among three inputs, traffic signal responses, a simple calculator, and character type checking. Each program prompts user input and provides output based on the conditions specified.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
PYTHON PROGRAMS WORKSHEET
The document contains a worksheet with Python programs that demonstrate decision-making using if-elif-else statements. It includes examples for number classification, voting eligibility, grade calculation, checking even or odd numbers, determining leap years, finding the largest number among three inputs, traffic signal responses, a simple calculator, and character type checking. Each program prompts user input and provides output based on the conditions specified.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
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.")