【发布时间】:2021-09-15 15:45:48
【问题描述】:
我最近开始了我的 Python 课程。在获得无效输入后,我想再次允许用户输入(回到问题的第一行),因此我在 while 循环中添加了。但是,现在,当输入为“是”时,python 会打印出“我不明白”。我能知道代码有什么问题吗?我应该如何修复它?
这里是代码
print('Hi, I am your bot, James!')
while True:
user_reply=input("Are you ready for today's activity? ")
if user_reply.lower == 'yes':
for_calculation()
elif user_reply.lower() == 'no':
while True:
double_confirm=input('Are you sure? ')
if double_confirm.lower() == 'yes':
print('See you next time.')
exit()
elif double_confirm.lower() == 'no':
for_calculation()
else:
print('I do not understand.')
else:
print('I do not understand.')
结果如下
Hi, I am your bot, James!
Are you ready for today's activity? yes
I do not understand.
Are you ready for today's activity?
【问题讨论】:
-
用
if user_reply.lower() == 'yes':替换if user_reply.lower == 'yes':
标签: python