0

Why does this code print No even if the answer is correct?

import random

num_1 = random.randrange(1, 15)
num_2 = random.randrange(1, 15)
score = 0
added = num_1 + num_2
answer = input("What is " + str(num_1) + " + " + str(num_2) + " = ")

if added == answer:
    print("Yes")
    score += 1
else:
    print("No")
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Code_Rik
  • 1
  • 1

1 Answers1

0

I think it's because the type of answer variable is string, while added variable is int.

You can change your code in a simple way :

if added == int(answer):

just adding int() in front of answer variable.

Suhan
  • 11
  • 1