如果选择是(是)
,如何从头开始重启{{1}}
答案 0 :(得分:1)
建议将其包装成一个函数:
def ask():
print " Please enter details: "
name = raw_input(" Employee Name: ")
hrs = float(raw_input(" Hours Per Week: "))
rate = float(raw_input(" Hourly Rate: "))
pay = hrs * rate
print ""
print "",name,":","Wage amount: "
print " ",pay,"Per week"
week = pay * 4
print " ",week,"Every 4 weeks"
print""
return raw_input("Restart? y/n: ") == "y"
done = ask()
while not done:
done = ask()
当然,您还应该考虑验证用户输入(例如,通过float()
抓住try/except
引发的错误。)
答案 1 :(得分:0)
def ask():
print (" Please enter details: ")
name = input(" Employee Name: ")
hrs = float(input(" Hours Per Week: ")
rate = float(input(" Hourly Rate: ")
pay = hrs * rate
print ("")
print (""),name,(":"),("Wage amount: ")
print (" "),pay,("Per week")
week = pay * 4
print (" "),week,("Every 4 weeks")
print("")
return input("Restart? y/n: ") == "y"
done = ask()
while not done:
done = ask()
我没有尝试过原始输入,似乎效果更好