Python 乘法测验语法错误
Python multiplication quiz syntax error
在编写一个总体上为用户创建包含 10 个乘法问题的测验的程序时,我遇到了一个语法错误,但未能成功修复。当我尝试 运行 代码时,出现语法错误,指向 "if userAns == numAns:" 之后的冒号 这是我的代码:
import random
numOne = 0
numTwo = 0
numRight = 0
numProblems = 0
numAns = 0
userAns = 0
while numProblems < 10:
numProblems+=1
numOne = random.randint(0,100)
numTwo = random.randint(0,100)
numAnswer = numOne*numTwo
userAnswer = int(input("What is:",numOne,"*",numTwo,"?")
if userAns == numAns:
numRight += 1
if numRight >0<3:
print("That was pretty bad.. ")
elif numRight >3 and numRight<=6:
print("Hey not bad..")
elif numRight >6 and numRight <=9:
print("You're pretty good....")
elif numRight == 10:
print("OK OK...You're smarter than me...")
else:
print("ERROR")
感谢您提供的任何帮助
此行需要一个右括号。
userAnswer = int(input("What is:",numOne,"*",numTwo,"?"))
而且你最好这样写提示信息:
...
while numProblems < 10:
numProblems+=1
numOne = random.randint(0,100)
numTwo = random.randint(0,100)
numAnswer = numOne*numTwo
hint = "What is:" + str(numOne) + "*" + str(numTwo) + "?"
userAnswer = int(input(hint))
if userAns == numAns:
numRight += 1
...
网上有几个问题userAnswer = ...
:
- 末尾缺少括号
input
需要一个参数
为了解决这些问题,试试这个:
userAnswer = int(input("What is: {} * {}? ".format(numOne, numTwo)))
在编写一个总体上为用户创建包含 10 个乘法问题的测验的程序时,我遇到了一个语法错误,但未能成功修复。当我尝试 运行 代码时,出现语法错误,指向 "if userAns == numAns:" 之后的冒号 这是我的代码:
import random
numOne = 0
numTwo = 0
numRight = 0
numProblems = 0
numAns = 0
userAns = 0
while numProblems < 10:
numProblems+=1
numOne = random.randint(0,100)
numTwo = random.randint(0,100)
numAnswer = numOne*numTwo
userAnswer = int(input("What is:",numOne,"*",numTwo,"?")
if userAns == numAns:
numRight += 1
if numRight >0<3:
print("That was pretty bad.. ")
elif numRight >3 and numRight<=6:
print("Hey not bad..")
elif numRight >6 and numRight <=9:
print("You're pretty good....")
elif numRight == 10:
print("OK OK...You're smarter than me...")
else:
print("ERROR")
感谢您提供的任何帮助
此行需要一个右括号。
userAnswer = int(input("What is:",numOne,"*",numTwo,"?"))
而且你最好这样写提示信息:
...
while numProblems < 10:
numProblems+=1
numOne = random.randint(0,100)
numTwo = random.randint(0,100)
numAnswer = numOne*numTwo
hint = "What is:" + str(numOne) + "*" + str(numTwo) + "?"
userAnswer = int(input(hint))
if userAns == numAns:
numRight += 1
...
网上有几个问题userAnswer = ...
:
- 末尾缺少括号
input
需要一个参数
为了解决这些问题,试试这个:
userAnswer = int(input("What is: {} * {}? ".format(numOne, numTwo)))