【发布时间】:2014-05-18 21:30:08
【问题描述】:
我正在设计一个程序来测试您输入随机引号的速度。我一直在尝试运行它,但它一直给我一个语法错误并突出显示 def 命令。我曾尝试篡改压痕,认为这就是问题所在。以下是全部代码:
import time, sys, random
random = ["Behind every great man is a woman rolling her eyes.", "A day without sunshine is like, you know, night.", "If the facts don't fit the theory, change the facts.","Housework can't kill you, but why take a chance?", "Weather forecast for tonight: dark."
def main():
ready = raw_input("Are you ready to begin?")
if ready == 'yes' or 'y':
print "3..."
time.sleep(1)
print "2..."
time.sleep(1)
print "1..."
time.sleep(1)
now = time.time()
quote = random.choice(random)
print quote
enter = raw_input()
future = time.time()
time = future - now
if enter == quote:
correct = "You had no mistakes."
else:
correct = "You had mistake(s)."
quote2 = len(quote)
wordlen = quote2 / 5
print "Results:"
print "The quote was "+quote2+" letters long and approx. "+wordlen+" words long."+correct+"Good job!"
if ready == 'no' or 'n':
print "Take your time."
sys.exit()
else:
print "What was that?"
main()
【问题讨论】:
-
阅读:显示的错误已修复,但现在它在 ln 7 上显示“UnboundLocalError: local variable 'time' referenced before assignment”。
-
您的评论应该是一个新问题,单独发布。现在您在这一个问题下有两个完全不同的问题的答案。
标签: python python-2.7 syntax function