[Solved] My Program is not printing what I want it to print


To match the symptoms reported I believe that your code is actually:

import random

name=input("Welcome to this Arithmetic quiz,please enter your name:")

score = 0

for i in range(10):
    number1=random.randint(20,50)

    number2=random.randint(1,20)
    oper=random.choice('+-*')
    correct_answer = eval(str(number1)+oper+str(number2))
    answer = (int(input('What is:'+str(number1)+oper+str(number2)+'=')) == correct_answer)
    if answer == correct_answer:
       print('Correct!')
       score +=1
    else:
       print('Incorrect!')
print("You got",score,"out of 10")

Note the indentation of the else statement is aligned with the if, not the for. Given that this line:

answer = (int(input('What is:'+str(number1)+oper+str(number2)+'=')) == correct_answer

assigns a boolean to the variable answer, not the answer that the user entered. You can do 2 things:

remove the == correct_answer part resulting in:

answer = int(input('What is:'+str(number1)+oper+str(number2)+'='))

or

change the if statement to:

if answer:

4

solved My Program is not printing what I want it to print