Questions
M3-R5.1 · Chapter 4: Operators, Expressions and Python Statements · 7 min read
Section 1: if-else Statements
Q1. Ask the user to enter a number. Check if it is even or odd. Print "Even" or "Odd".
Q2. Take a temperature value (in Celsius) as input. If it is above 37.5, print "Fever detected." Otherwise print "Normal temperature."
Q3. Ask the user to enter their exam marks (out of 100). If marks are 40 or more, print "Pass." Otherwise print "Fail."
Q4. Accept two numbers from the user. Print the larger number. If they are equal, print "Both are equal."
Q5. Ask for a year. Check whether it is a leap year or not. A year is a leap year if divisible by 4.
Q6. Take a word as input. If the word starts with a vowel (a, e, i, o, u), print "Starts with a vowel." Otherwise print "Starts with a consonant."
Q7. Ask the user to enter a password. If the length of the password is less than 8 characters, print "Weak password." Otherwise print "Strong password."
Q8. Accept a number and check if it is positive or negative. Print the result accordingly.
Q9. Ask the user to enter two numbers and an operator (+ or -). Perform the operation and print the result.
Q10. Take a product price as input. If the price is more than 1000, apply a 10% discount and print the discounted price. Otherwise print the original price.
Hint: Multiply price by 0.9 for discount
Section 2: if-elif-else Statements
Q11. Ask the user for their score (0-100). Print a grade: A (90+), B (75-89), C (60-74), D (40-59), F (below 40).
Hint: Use elif for each range
Q12. Ask for the current hour (0-23). Print "Good morning" (5-11), "Good afternoon" (12-16), "Good evening" (17-20), or "Good night" (otherwise).
Hint: Check ranges with and operator
Q13. Accept a number from the user. Print whether it is positive, negative, or zero.
Q14. Ask for a day number (1-7). Print the name of the day (1 = Monday, 7 = Sunday). If out of range, print "Invalid day."
Q15. Take a person's BMI as input. Classify: Underweight (< 18.5), Normal (18.5-24.9), Overweight (25-29.9), Obese (30+).
Hint: Use float input and compare range
Q16. Ask the user to enter a month number (1-12). Print the number of days in that month (ignore leap years). If invalid, print "Invalid month."
Hint: Group months with same days using or
Q18. Ask the user to enter their internet speed in Mbps. Print: "Slow" (< 5), "Basic" (5-25), "Fast" (26-100), "Ultra Fast" (> 100).
Hint: Use elif with integer comparisons
Q19. Take a shopping bill amount. Apply discounts: 20% if bill > 5000, 10% if bill > 2000, 5% if bill > 1000. Print final amount.
Hint: Check from highest condition first
Q20. Ask the user to pick a season (1-4). Print the months that belong to that season. Print "Invalid" for other inputs.
Hint: Each elif maps a number to month
Section 3: Nested if Statements
Q21. Ask for age and whether the user has a driving license (yes/no). If age >= 18, check license. If yes, print "Allowed to drive." If no, print "Get a license first." If under 18, print "Too young to drive."
Q22. Ask a user for their username and password. If username is correct, check the password. If both match, print "Login successful." If password is wrong, print "Wrong password." If username is wrong, print "User not found."
Q23. Ask for a number. First check if it is positive. If yes, check whether it is even or odd. If negative, print "Negative number."
Hint: Outer if checks sign, inner checks parity
Q24. Ask the user for their marks and whether they passed the practical exam (yes/no). If marks >= 40, check practical. If practical passed too, print "Overall Pass." Otherwise "Failed in practical." If marks < 40, print "Failed in theory."
Hint: Two conditions to pass - both must be true
Q25. Ask the user for a country. If the country is "India", ask for the state. If the state is "UP", print "Welcome to Uttar Pradesh." Else print "Welcome to India." If other country, print "Welcome!"
Hint: String comparison with ==
Q26. Ask a user if they are a member (yes/no). If yes, ask for their membership type (gold/silver). Gold members get 30% off, silver get 15% off. Non-members get no discount.
Hint: Nested if inside the member branch
Q27. Take two numbers and an operation (multiply or divide). If divide, check if the second number is zero before dividing. Print an error if it is.
Hint: Outer if selects operation, inner checks zero
Q28. Ask whether a student submitted their assignment (yes/no). If yes, check if it was on time (yes/no). Print: "Full marks", "Late penalty applied", or "No marks - not submitted."
Hint: Three possible output paths
Q29. Ask for a product category (electronics/clothing/food). For electronics, check if price > 10000 for a luxury tax message. For clothing, check if it is on sale. For food, always print "No tax."
Hint: Outer if selects category, inner adds detail
Q30. Ask the user for temperature and whether it is raining (yes/no). If temp > 30 and not raining, print "Hot and sunny." If temp > 30 and raining, print "Hot and rainy." If temp <= 30 and raining, print "Cool and rainy." Otherwise print "Cool and clear."
Hint: Outer checks temperature, inner checks rain