Python 2.7 为什么我的程序不能用python工作?
嗨,我11岁了,我正在自学如何编码。我给自己安排了一个任务,做一个时间表测验,问10个问题,输入随机数。然而,我的代码不起作用,我不知道为什么。我正在使用python 2.7.5。这是我的代码:Python 2.7 为什么我的程序不能用python工作?,python-2.7,Python 2.7,嗨,我11岁了,我正在自学如何编码。我给自己安排了一个任务,做一个时间表测验,问10个问题,输入随机数。然而,我的代码不起作用,我不知道为什么。我正在使用python 2.7.5。这是我的代码: print("Here is a quiz to test your knowledge") print("") print("Question 1") import random print random.randint(1,10) print ("times") import random prin
print("Here is a quiz to test your knowledge")
print("")
print("Question 1")
import random
print random.randint(1,10)
print ("times")
import random
print random.randint(1,10)
answer = raw_input ("Make your choice: ")
if answer == ran1*ran2:
print "That is correct"
correct=correct +1
else:
print "That is incorrect!"
我不知道为什么它不工作,但我还没有把一个for循环,所以它只问了一个问题。当我运行它时,else以红色突出显示,但我不知道为什么。Python在没有括号的情况下工作。它被空格或制表符替换。我们进口一次,开始 这应该行得通
import random
print("Here is a quiz to test your knowledge")
print("")
print("Question 1")
print random.randint(1,10)
print ("times")
print random.randint(1,10)
answer = raw_input ("Make your choice: ")
if answer == ran1*ran2:
print "That is correct"
correct=correct +1
else:
print "That is incorrect!"
欢迎来到StackOverflow!是否您忘记了在if和else之间缩进语句?这三行分别表示正确、正确=正确+1和不正确!前面应该有四个空格。