Python Exercise - Control Flow with if, elif, and else
Introduction
This unit focuses on Python’s control flow structures, particularly using if
, elif
, and else
. You’ll create small programs to practice decision-making and flow control based on user input.
Task 1: Age Verification
Description:
Write a program that checks if the user’s age qualifies as being an adult.
Instructions:
- Prompt the user to enter their age.
- Use an
if
statement to check if the age is 18 or older. - If true, print “You are an adult.”
Task 2: Even or Odd Number
Description:
Write a program that determines if a given number is even or odd.
Instructions:
- Prompt the user to enter a number.
- Use
if
andelse
to check if the number is divisible by 2. - Print “The number is even” for even, and “The number is odd” for odd.
Task 3: Grade Evaluation
Description:
Create a program that evaluates a student’s grade and assigns a classification based on a scoring scale.
Instructions:
- Prompt the user to enter a grade between 0 and 100.
- Use
if
,elif
, andelse
to categorize the grade as follows:- 90 and above: “Excellent”
- 80 to 89: “Good”
- 70 to 79: “Satisfactory”
- 60 to 69: “Pass”
- 50 to 59: “Poor”
- Below 50: “Fail”
Task 4: Temperature Classification
Description:
Write a program that classifies the temperature in Celsius.
Instructions:
- Prompt the user to enter a temperature in Celsius.
- Use
if
,elif
, andelse
to classify the temperature as:- 30°C or higher: “Hot”
- 20°C to 29°C: “Warm”
- 10°C to 19°C: “Cool”
- Below 10°C: “Cold”