This Python program is an implementation to CS50’s Introduction to Programming with Python Week 3 - Felipe’s Taqueria Problem Set, named taqueria.py
, simulates an order system for Felipe's Taqueria. The program allows a user to place an order by inputting menu items. After each input, the program displays the total cost of all items inputted so far, formatted as a dollar amount with two decimal places. The program treats the user's input case insensitively and ignores any input that isn't a valid menu item.
-
Open your terminal.
-
Navigate to the directory where you have saved the
taqueria.py
file.cd path/to/your/directory
-
Run the program using the Python interpreter:
python taqueria.py
-
The program will prompt you to enter menu items one by one. After each input, it will display the updated total cost of all items inputted so far.
# taqueria.py
def main():
menu = {
"Baja Taco": 4.00,
"Burrito": 7.50,
"Bowl": 8.50,
"Nachos": 11.00,
"Quesadilla": 8.50,
"Super Burrito": 8.50,
"Super Quesadilla": 9.50,
"Taco": 3.00,
"Tortilla Salad": 8.00
}
total = 0
while True:
try:
item = input("Item: ")
if item.capitalize() in menu or item.title() in menu:
for dish in menu:
if item.capitalize() == dish or item.title() == dish:
total += menu[dish]
print(f"Total: ${total:.2f}")
except EOFError:
break
if __name__ == "__main__":
main()
- Run the program as mentioned in the "How to Run the Program" section.
- Follow the prompts to enter various menu items. Make sure to test both upper and lower case inputs, as well as mixed case inputs.
- After each input, the program will display the total cost of all items entered so far.
- When you're done entering items, press
Ctrl-D
(orCtrl-Z
on Windows) to signal the end of input. The program will exit, and your order summary will be displayed.
-
Input: Taco (or taco) and Taco Result: Total: $6.00
-
Input: Baja Taco (or baja taco) and Tortilla Salad (or tortilla salad) Result: Total: $12.00
-
Input: Burger Result: (no output)
Make sure to save the taqueria.py
file in the same directory where you are running the program. If you encounter any issues with the program not being found or not running as expected, ensure you are in the correct directory and have saved the file with the correct name.