问:为什么当我有多个整数时,我的计数功能只计算为1?
CODE:
import random
while True:
value = 0
count = 0
right_counter = 0
value = int(input("Enter the amount of questions would you like to answer: "))
AVG = right_counter / value
if 0<=value<=10:
for i in range(value):
numb1 = random.randint(0, 12)
numb2 = random.randint(0, 12)
answer = numb1 * numb2
AVG = right_counter / value
problem = input("What is " + str(numb1) + " * " + str(numb2) + "? ")
right_counter =+ 1
if int(problem) == answer:
print("You are Correct! Great Job!".format(right_counter))
elif int(problem) > answer:
print("Incorrect, Your answer is too high!")
elif int(problem) < answer:
print("Incorrect, your answer is too low!")
print("You got",right_counter,"out of",value,"correct, giving you an average of ",AVG,"")
break
else:
print(" Error, Please type a number 1-10 ")
这是输出的样子:
输入您想回答的问题数量:3
什么是1 * 8? 8
你是对的!干得好!
什么是11 * 11? 122个
不正确,你的回答太高了!
什么是1 * 7? 7
你是对的!干得好!
你有3分中有1分正确,平均分为0.3333333333333333
我在Tutorial找到了一些帮助,但我无法回答我的问题。
答案 0 :(得分:2)
虫:
right_counter =+ 1
这是(阴险地)相当于
right_counter = 1
你可能意味着
right_counter += 1
您可能还想解决right_counter
增加的逻辑问题,无论答案的正确性如何。