<p>我正在完成Eric Matthes的Python速成班的教科书作业</p>
<p>代码按照说明运行,但我想解决三个问题,但不知道如何解决。问题是:(1)我不知道我是否正确使用了该标志。(2) 我使用int()操作用户输入,以便将用户值与整数进行比较。(3) 如果用户输入'quit',程序将崩溃并显示错误(ValueError:int()的无效文本,以10为基数:“quit”)。这与我的第二期有关</p>
<p>谢谢你的帮助</p>
<p>大卫</p>
<p>--
说明:
电影院根据人的年龄收取不同的票价。如果一个人未满3岁,车票是免费的;如果他们在3到12岁之间,票价是10美元;如果他们超过12岁,票价是15美元。写一个循环,询问用户的年龄,然后告诉他们电影票的价格</p>
<pre><code>prompt = "\nI will price your ticket. What is your age?"
active = True #Per Matthes, using the flag Active, a program "should run while
#the flag is set to True and stop running when any of several events sets the
#value of the flag to False."
while active:
message = int(input (prompt))
if message < int(3):
print("Your ticket is free!")
elif int(3) <= message <= int(12):
print("Your ticket is $10!")
elif message > int(12):
print("Your ticket is $15!")
else:
active = False
break #Per Matthes, the break statement will force the program "to exit
#a while loop immediately without running any remaining code in the
#loop."
</code></pre>