0
0
Pythonprogramming~15 mins

If–else execution flow in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else Execution Flow
📖 Scenario: You are building a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Create a program that uses if-else statements to decide if a person can vote based on their age.
📋 What You'll Learn
Create a variable called age with the exact value 20
Create a variable called voting_age and set it to 18
Use an if-else statement to check if age is greater than or equal to voting_age
Print You can vote! if the person is old enough
Print You cannot vote yet. if the person is too young
💡 Why This Matters
🌍 Real World
Programs often need to make decisions based on conditions, like checking age for voting or permissions.
💼 Career
Understanding if-else statements is fundamental for any programming job because it controls the flow of decisions.
Progress0 / 4 steps
1
Create the age variable
Create a variable called age and set it to the number 20.
Python
Need a hint?

Use = to assign the value 20 to the variable age.

2
Set the voting age
Create a variable called voting_age and set it to 18.
Python
Need a hint?

Voting age is usually 18. Assign this number to voting_age.

3
Write the if-else statement
Use an if-else statement to check if age is greater than or equal to voting_age. Use the exact variables age and voting_age in your condition.
Python
Need a hint?

Use if age >= voting_age: to start the condition. Then add else: for the other case.

4
Display the result
Run the program and print the output. The program should print You can vote! because age is 20.
Python
Need a hint?

Just run the program. It will print the correct message based on the age.