按钮Mash游戏

时间:2017-09-20 17:09:41

标签: python

我想创建一个游戏,其中的想法是在时间限制内尽可能多地发送垃圾邮件:10秒

import time
import random
print("Spamming race")
print("*************")
time.sleep(10)
print("You must spam the number '1'.")
time.sleep(3)
print("Ready")
time.sleep(1)
print("Set")
no = (0.25,0.5,0.7,1,1.25,1.5,1.7,2,2.25,2.5,2.75,3)
number = random.choice(no)
time.sleep(number)
print("Go!")

max_time = 1
t = 31
start_time = time.time()
g = input()

if time.time - start_time > max_time > t:      #where the problem is but I don't know why
    distance = g.count('1')
    print("And he crosses the line with a distance of ",distance)

它说问题出在第23行,但我无法看到有人可以帮助我的问题是什么?

2 个答案:

答案 0 :(得分:0)

正如@Rawing指出的那样,你忘了打电话给time.time

if time.time()-start_time>max_time>t:
     distance=g.count('1')
     print("And he crosses the line with a distance of ",distance)

答案 1 :(得分:0)

Rawing是正确的。要详细说明,请使用time.time()而不是time.time 我想你想要的是:

if(time.time() - start_time)> t: