<p>您的代码在流控制(<code>if</code>块)和值分配(<code>==</code>和<code>=</code>)方面存在各种问题。经过一些改动后,就到了。
尽量不要把4个空格的标签和8个空格的标签混在一起。始终使用4空格标签,因为它是PEP8的标准标签</p>
<pre><code>while True:
beverage = input("What is your preferred beverage: coffee, or tea?").lower() # much efficient to .lower() only once
if beverage in ('coffee','tea','t','c'): # Change this to 'in'
if beverage == 't' or beverage == 'tea':
beverage = 'tea' # value assignments are done with = not ==
elif beverage == 'c' or beverage == 'coffee':
beverage = 'coffee' # value assignments are done with = not ==
print('Ah! Fantastic choice!')
print('You have chosen {}'.format(beverage))
else:
print("Sorry! I didn't quite catch that. Please try again! (Note that you can use the letter 'c' or the letter 't' to denote coffee or tea respectively!)")
</code></pre>
<p>O/p:</strong></p>
<pre><code>What is your preferred beverage: coffee, or tea?c
Ah! Fantastic choice!
You have chosen coffee
What is your preferred beverage: coffee, or tea?t
Ah! Fantastic choice!
You have chosen tea
What is your preferred beverage: coffee, or tea?x
Sorry! I didn't quite catch that. Please try again! (Note that you can use the letter 'c' or the letter 't' to denote coffee or tea respectively!)
</code></pre>