【发布时间】:2017-05-18 01:12:24
【问题描述】:
如果您等待 4 秒,它会显示“您的时间已用完”,这很好。但是,要继续循环,您必须按enter 键才能继续。
我希望当它在下面打印“你没有时间”而不是仅仅输入时,它会显示一个输入语句,例如“输入'攻击'以继续进行”,并且循环将从原来的位置继续。
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)
【问题讨论】:
-
@abccd 我不完全确定我的意思是从他的回复中得到什么 我对线程和线程仍然很陌生,你能告诉我需要去哪里吗?谢谢,它必须有一个功能还是我们仍然可以使用我的大部分版本?
-
您使用的是哪个操作系统?
-
Mac OS 最新python
标签: python python-3.x