【发布时间】:2016-02-24 00:05:32
【问题描述】:
我一直在编写关于外部代码源的计算机科学作业,计算出有人猜一个问题需要多长时间。
但是当我运行它时,我收到了这个错误:
Traceback (most recent call last):
File "E:/Documents/Guess band member.py", line 14, in <module>
start = time.time()
AttributeError: 'float' object has no attribute 'time'
如果有人能帮我解决这个问题,我将不胜感激。
import time
print("You can type 'quit' to exit")
Exit = False
Band = ["harry", "niall", "liam", "louis" ]
while Exit == False:
print("Guess a band member")
start = time.time()
Guess = input(":")
end = time.time()
Guess = Guess.lower()
if Guess == 'quit':
Exit = True
elif Guess in Band:
print("You're right")
elif Guess == "zayn":
print("Wrong")
print("He left.")
else:
print("Fool!")
time = end - start
print("You took", time, "seconds to guess.")
【问题讨论】:
-
time = end - start?
标签: python time while-loop return