P_30 Coding Exercise for Beginners in Python | Exercise 9 | Python Tutorials for Beginners
Automatic Pizza Order Program
Overview of the Exercise
- The video introduces a coding exercise to create an automatic pizza order program, building on previous lessons about multiple if statements in Python.
- The goal is to calculate the final bill based on user input regarding pizza size and additional toppings.
Pricing Structure
- Small pizza costs 100 rupees, medium pizza costs 200 rupees, and large pizza costs 300 rupees. Additional charges apply for toppings: pepperoni adds 30 rupees for small pizzas and 50 rupees for medium or large pizzas; extra cheese adds 20 rupees regardless of size.
User Input Process
- Users are prompted to select their desired pizza size, which will determine the initial bill amount. The program should handle various inputs (small, medium, large) using conditional statements. If an invalid input is provided, a warning message should be displayed.
Conditional Logic Implementation
- The program initializes the bill at zero and uses if/elif/else statements to update the bill based on user selections:
- For small pizzas: add 100 rupees.
- For medium pizzas: add 200 rupees.
- For large pizzas: add 300 rupees.
- If an invalid size is entered, prompt for valid input.
Adding Toppings
- After selecting the pizza size, users are asked if they want to add pepperoni:
- If yes and the size is small, add 30 rupees; if medium or large, add 50 rupees.
- Users are then asked about extra cheese; adding it increases the total by 20 rupees regardless of size. This logic also utilizes conditional checks for user responses (yes/no).
Final Output
- Once all conditions have been processed and calculations made, the program outputs the final bill using formatted strings (f-string). Users are encouraged to dry run their code with different inputs before compiling it on their systems. Examples of expected outputs are provided during this section of the video.