for a in list:
answer_or_help = False
print(a.question)
while answer_or_help not in ("q", "a"):
answer_or_help = input("Press a for Answer, h for Help, q to quit: ")
if answer_or_help == "h":
print(a.hint)
elif answer_or_help == "a":
print(a.answer)
elif answer_or_help != "q":
print("This is not a valid answer")
else:
if answer_or_help == "q":
break
当我键入“ q”时,我正在尝试退出FOR循环,但不确定这是否是最好的方法。
我将不胜感激任何帮助。谢谢!!
假设每个对象有一个问题。您不需要while
。input()
函数将无限期等待用户输入。
idx = 0
while idx < len(your_list):
obj = your_list[idx]
print(obj.question)
answer_or_help = input("Press a for Answer, h for Help, q to quit: ")
if answer_or_help == 'q':
break
elif answer_or_help == "h":
print(obj.hint)
elif answer_or_help == "a":
print(obj.answer)
idx += 1 # moving object
else:
print("This is not a valid answer")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句