Today I covered conditional statements in Python.
For practice, I made a pizza ordering system. How it works is the user is asked 3 questions: What size pizza they want (small, medium or large), if they want pepperoni and finally, if they want extra cheese.
These 3 questions are stored in 3 variables with an input function.
I started by creating an additional variable named 'bill' and then writing the conditional statements:
bill = 0
if size == "S":
bill += 15
if add_pepperoni == "Y":
bill += 2
The above code was followed by 'else if' statements to trigger the other conditions if the first one wasn't true.
I created a separate if statement to determine if the price of extra cheese was going to be added to the bill:
if extra_cheese == "Y":
bill += 1
print(f"Your final bill is: ${bill}.")
Below is an example of the final result:
Welcome to Python Pizza Deliveries!
What size pizza do you want? S, M, or L M
Do you want pepperoni? Y or N Y
Do you want extra cheese? Y or N Y
Your final bill is: $24.
Top comments (0)