-1
import random

questions = 1
score = 0

input("Please enter your name: ")

operator = ["+","-","*"]

while questions<10:
  num1 = (random.randint(0,15))
  num2 = (random.randint(0,15))
  picked_operator = random.choice(operator)
  print("What is " + str(num1) +str(picked_operator) +str(num2), "?")
  question = '{} {} {}'.format(num1, picked_operator, num2)
  answer = input()
  if answer == eval(question): 
    print("You are correct")
    score = score+1
  else:
    print("incorrect")
  questions = questions + 1  
  print(answer)

example of what is printed: please enter your name: dan what is 11 + 3? 14 incorrect 14 what is 13-7? ................

2 Answers2

0

The error is with your input() statement. Use this instead:

answer = int(input())

# OR

if answer == str(eval(question)):
    # Do things

You're accepting answer as a string quantity, and comparing it with an integer, see below:

>>> 12 == '12'
False
Codeman
  • 477
  • 3
  • 13
0

The eval function in Python returns an Integer, and the input function returns a String. When you compare Int with Str, you will not get equal.

answer = int(input())

it should be good like that

Mario Khoury
  • 372
  • 1
  • 7