0
0
Pythonprogramming~15 mins

Nested conditional execution in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Execution
📖 Scenario: You are creating a simple program to help a coffee shop decide the price of a coffee order based on the size and whether the customer wants extra syrup.
🎯 Goal: Build a program that uses nested if statements to determine the final price of a coffee order based on size and syrup choice.
📋 What You'll Learn
Create a variable size with exact values: 'small', 'medium', or 'large'
Create a variable extra_syrup with exact boolean values: True or False
Use nested if statements to set the price based on size and extra_syrup
Print the final price as a float with two decimal places
💡 Why This Matters
🌍 Real World
Coffee shops and many businesses use nested conditions to decide prices or options based on multiple choices customers make.
💼 Career
Understanding nested conditions is important for writing clear decision-making code in software development, especially in user input handling and business logic.
Progress0 / 4 steps
1
Set up the coffee order variables
Create a variable called size and set it to the string 'medium'. Create another variable called extra_syrup and set it to True.
Python
Need a hint?

Use = to assign values. Strings need quotes, booleans are True or False.

2
Create a base price variable
Create a variable called price and set it to 0.0 as a starting point for the coffee price.
Python
Need a hint?

Start with a price of zero before deciding the final price.

3
Use nested if statements to set the price
Use nested if statements with size and extra_syrup to set price as follows:
- If size is 'small', price is 2.0, add 0.5 if extra_syrup is True.
- If size is 'medium', price is 3.0, add 0.5 if extra_syrup is True.
- If size is 'large', price is 4.0, add 0.5 if extra_syrup is True.
Python
Need a hint?

Check the size first, then inside that check if extra_syrup is True to add 0.5.

4
Print the final price
Print the price variable formatted to two decimal places using print(f"{price:.2f}").
Python
Need a hint?

Use an f-string to format the price with two decimals.