如果在输入错误的输入时如何防止重复“再试一次”:
from __future__ import print_function
print("Hello, World!")
name = input("What is your name?")
hobby = input("Cool, so " + name + " what do you do you for fun? You can say something like play, work, learn, etc.")
actions = {'play': 'awesome', 'work': 'must be busy', 'learn': 'ha, me too', }
while True:
try:
print(actions[hobby])
break
except KeyError:
print("Try again.")