Felipe’s Taqueria

One of the most popular places to eat in Harvard Square is Felipe’s Taqueria, which offers a 菜单 of entrees, per the dict below, wherein the value of each key is a price in dollars:
{
"Baja Taco": 4.25,
"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
}
In 名为 taqueria.py, 实现一个 program that enables a user to place an order, prompting them for items, one per line, until the user inputs control-d (which is a common way of ending one’s input to a program). After each inputted item, display the total cost of all items inputted thus far, prefixed with a dollar sign ($) and formatted to two decimal places. Treat the user’s input case insensitively. Ignore any input that isn’t an item. 假设 every item on the 菜单 will be titlecased.
提示
- 笔记 that you can detect when the user has inputted control-d by catching an
EOFErrorwith code like:try: item = input() except EOFError: ...You might want to print a new line so that the user’s cursor (and subsequent prompt) doesn’t remain on the same line as your program’s own prompt.
- Inputting control-d does not require inputting Enter as well, and so the user’s cursor (and subsequent prompt) might thus remain on the same line as your program’s own prompt. You can move the user’s cursor to a new line by printing
\n自己! - 笔记 that a
dictcomes with quite a few methods, per docs.python.org/3/library/stdtypes.html#mapping-types-dict, among themget, and supports operations like:d[key]and
if key in d: ...wherein
dis adictandkeyis astr. - 请务必 avoid or catch any
KeyError.
演示
Before You Begin
- Log into cs50.dev using your GitHub account.
- Click inside the terminal window and execute
cd. - Execute
wget https://cdn.cs50.net/2022/fall/实验s/6/taqueria.zipfollowed by Enter in order to 下载 a zip calledtaqueria.zipin your codespace. Take care not to overlook the space betweenwgetand the following URL, or any other character for that matter! - Now execute
unzip taqueria.zipto create 的文件夹中名为taqueria. - You 不再 need the ZIP file, so you can execute
rm taqueria.zipand respond with “y” followed by Enter at the prompt.
如何测试
Here’s how to test your code manually:
- Run your program with
python taqueria.py. TypeTacoand press Enter, then typeTacoagain and press Enter. 你的程序应该 output:Total: $6.00and continue prompting the user until they input control-d.
- Run your program with
python taqueria.py. TypeBaja Tacoand press Enter, then typeTortilla Saladand press enter. 你的程序应该 output:Total: $12.25and continue prompting the user until they input control-d.
- Run your program with
python taqueria.py. TypeBurgerand press Enter. 你的程序应该 re提示用户.
请务必 try other foods and vary the casing of your input. 你的程序应该 behave as expected, 不区分大小写ly.
You can execute the below to check your code using check50, a program that CS50 will use to test your code when you 提交. But be sure to test it自己 as well!
check50 cs50/problems/2022/python/taqueria
Green smilies 意思 your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that check50 outputs to see the input check50 handed to your program, what output it expected, and what output your program actually gave.
如何提交
No need to 提交! This is a 练习题.