如果你等待4秒钟,它会显示 "你已经超时" 的提示,这是好的。但是,为了让循环继续进行,你需要按
我希望在它打印出 "你已经超时" 后,它能够显示一个输入提示语句,比如说 "输入 'attack' 继续",这样循环就能从上一次的位置继续下去。
enter
键继续。我希望在它打印出 "你已经超时" 后,它能够显示一个输入提示语句,比如说 "输入 'attack' 继续",这样循环就能从上一次的位置继续下去。
from threading import Timer
import time
monsterhp = int(800)
y = 150
while monsterhp > 0:
timeout = 4
t = Timer(timeout, print, ['You ran out of time.'])
t.start()
print(" ")
prompt = "You have %d seconds Type 'attack' to hit the monster\nType here: " % timeout
answer = input(prompt)
t.cancel()
if answer == "attack":
print("You strike the monster")
time.sleep(1)
monsterhp = monsterhp - y
print("War Lord Health:", monsterhp)