Laboratory Exam: If-Else Statements in Python
Instructions:
• Write Python programs to solve each of the problems below.
• Ensure your code is properly formatted and includes comments where necessary.
• Test your program with different inputs to validate correctness.
Part 1: Basic If-Else (4 points each)
Problem 1: Write a Python program that asks the user to enter a number. The program should
check if the number is positive, negative, or zero and display the appropriate message.
Problem 2: Write a Python program that asks the user for a number and checks whether it is
even or odd. Display the result.
Problem 3: Create a Python program that determines if a given year is a leap year. A year is a
leap year if it is divisible by 4 but not divisible by 100, unless it is also divisible by 400.
Problem 4: Write a program that asks the user to enter their age and checks if they are eligible to
vote (18 years and above).
Problem 5: Write a Python program that takes three numbers as input and determines the largest
among them.
Part 2: Nested If-Else and Logical Operators (10 points each)
Problem 6: Write a program that asks the user to enter a password. If the password matches
"PythonRocks123", print "Access Granted"; otherwise, print "Access Denied." If the password is
incorrect and contains the word "Python", print "Close, but not quite!".
Problem 7: A company gives a discount based on the total purchase amount:
• If the amount is more than $1000, the discount is 10%.
• If the amount is between $500 and $1000 (inclusive), the discount is 5%.
• Otherwise, no discount is applied. Write a program that takes the total purchase amount
as input and outputs the final amount after applying the discount.
Problem 8: Write a Python program that simulates a simple grading system:
• 90 and above: "A"
• 80-89: "B"
• 70-79: "C"
• 60-69: "D"
• Below 60: "F" The program should ask the user for their score and display the
corresponding grade.
Problem 9: Create a program that asks the user to input the current temperature in Celsius.
Based on the input, categorize the weather:
• Below 0°C: "Freezing"
• 0°C - 15°C: "Cold"
• 16°C - 25°C: "Mild"
• 26°C - 35°C: "Warm"
• Above 35°C: "Hot"