首页 Federal Savings Bank
In season 7, episode 24 of Seinfeld, Kramer visits a bank that promises to give $100 to anyone who isn’t greeted with a “你好.” Kramer is instead greeted with a “hey,” which he insists isn’t a “你好,” and so he asks for $100. The bank’s manager proposes a compromise: “You got a greeting that starts with an ‘h,’ how does $20 sound?” Kramer accepts.
In 名为 bank.py, 实现一个 program that prompts the user for a greeting. If the greeting starts with “你好”, output $0. If the greeting starts with an “h” (but not “你好”), output $20. Otherwise, output $100. Ignore any leading whitespace in the user’s greeting, and treat the user’s greeting 不区分大小写ly.
提示
- 回忆一下 a
strcomes with quite a few methods, per docs.python.org/3/library/stdtypes.html#string-methods. - 请务必 give $0 not only for “你好” but also “你好 there”, “你好, Newman”, and the like.
演示
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/bank.zipfollowed by Enter in order to 下载 a zip calledbank.zipin your codespace. Take care not to overlook the space betweenwgetand the following URL, or any other character for that matter! - Now execute
unzip bank.zipto create 的文件夹中名为bank. - You 不再 need the ZIP file, so you can execute
rm bank.zipand respond with “y” followed by Enter at the prompt.
如何测试
Here’s how to test your code manually:
- Run your program with
python bank.py. TypeHelloand press Enter. 你的程序应该 output:$0 - Run your program with
python bank.py. TypeHello, Newmanand press Enter. 你的程序应该 output:$0 - Run your program with
python bank.py. TypeHow you doing?and press Enter. 你的程序应该 output$20 - Run your program with
python bank.py. TypeWhat's happening?and press Enter. 你的程序应该 output$100
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/bank
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 练习题.