0
处理此代码。当程序运行时,print(random_generator)
实际上并没有打印出报价,它只是在shell中表示<function 40x....>
。任何提示为什么发生这种情况?功能不正确返回列表
import time
import random
quotes= ["Life is too short, so savior every moment",
"Here's to the crazy ones, the rebels, square pegs in round holes",
"You miss all the shots you don't take"]
def random_generator(): #RandomQuoteGenerator
return random.choice(quotes)
timeout = 1 #Timer
first_time = time.time()
last_time = first_time
while(True):
pass #do something here
new_time = time.time()
if new_time - last_time > timeout:
last_time = new_time
print(random_generator)
print ("Its been %f seconds" % (new_time - first_time)) #TimeCheck
'打印(random_generator())'。我怀疑你需要真正调用这个函数。 – NightShadeQueen