1
import random

while True:
    calc_1 = (random.randint(1,50)) #generates random variables
    calc_2 = (random.randint(1,50))
    print (calc_1,"+",calc_2)       #prints the random question
    a = ((calc_1)+(calc_2))         #calculates the random question
    q = input ("? ")
    if q == a :
        print ("right")
        break
    else:
        print ("wrong")

It won't say right, when the answer is right. I already tested a few other possibilities but I couldn't figure it out.

MBT
  • 21,733
  • 19
  • 84
  • 102
  • Hmm. A better duplicate is this one: https://stackoverflow.com/q/26447498/270986. Or this one: https://stackoverflow.com/q/50241056/270986 – Mark Dickinson Aug 30 '18 at 16:11
  • Works fine for me once I took out the "Enter code here" comment. – Duston Aug 30 '18 at 16:12
  • Possible duplicate of [If...else statement issue with raw\_input on Python](https://stackoverflow.com/questions/26447498/if-else-statement-issue-with-raw-input-on-python) – mkrieger1 Aug 30 '18 at 18:32
  • I'm using Python 2.7.11 on Ubuntu 16.04 – Duston Aug 30 '18 at 19:10

1 Answers1

0

input() gives you str so convert it to int before comparison

import random

while True:
    calc_1 = (random.randint(1, 50))  # generates random variables
    calc_2 = (random.randint(1, 50))
    print(calc_1, "+", calc_2)  # prints the random question
    a = ((calc_1) + (calc_2))  # calculates the random question
    q = input("? ")
    try:
        q = int(q)
        if q == a:
            print("right")
            break
        else:
            print("wrong")
    except:
        print('Not a number')
daemon24
  • 1,388
  • 1
  • 11
  • 23