def checkAnswer(number1, number2, answer, right):
print (number1)
print (number2)
print (answer)
print (right)
if answer == number1 + number2:
print ("Right")
right = right + 1
else:
print ("Wrong")
return right
I tried debugging my code by printing all the values that came as parameters to the function. number1 and number2 are equal to the answer that the user inputs, but the if/else statement goes to the else statement.
Here is my main function:
def main():
#Initialize variables
counter = 0
studentName = ""
averageRight = 0.
right = 0
number1 = 0
number2 = 0
answer = 0
#Take the student's name as input for personalization
studentName = inputNames(studentName)
#Loop the program 10 times
while counter < 10:
number1, number2 = getNumbers()
answer = getAnswer(number1, number2)
right = checkAnswer(number1, number2, answer, right)
counter = counter + 1
I am making a "math test" that loops ten times, and each loop consists of a simple addition problem with random ints from 1 to 500. The user then inputs answer and the program stores an int that holds the number of correct answers out of ten in right
Aucun commentaire:
Enregistrer un commentaire