Glayce
Glayce

Reputation: 61

Comparitive if statement not working?

This code is not working, any help? The main problem is:

while True:
    x1 = input("what's a?")
    if x1 == a:
        delay("a is correct!")
        x2 = input("what's b?")
        if x2 == b:
            delay("you're correct!")
            delay("bye")
            break

Here's the full code for reference:

from random import randint
from time import sleep
def delay(x):
    print(x)
    sleep(0.4)
delay("Welcome to the adding game")
delay("two numbers will be randomly generated")
delay("we'll call then a and b")
delay("We'll show you a+b first")
delay("then a-b")
delay("use that information to then determine the answer")
input("ready?")
a = randint(1,15)
b = randint(1,15)
print("a+b = ",a+b)
print("a-b = ",a-b)
print(a,b)
while True:
    x1 = input("what's a?")
    if x1 == a:
        delay("a is correct!")
        x2 = input("what's b?")
        if x2 == b:
            delay("you're correct!")
            delay("bye")
            break
        else:
            delay("wrong")
    else:
        delay("you're wrong")
        x3 = input("what's b?")
        if x3 == b:
            delay("that's correct!")
            delay("now use that info to figure out a")
        else:
            delay("wrong again")
            delay("look at the numbers and try again")

Upvotes: 0

Views: 47

Answers (1)

Kirill
Kirill

Reputation: 449

input() returns a string, and a and b are integers, so comparing them won't work.

x1 = int(input("what's a?")), and likewise for x2 and x3, will make the comparisons work as expected.

Upvotes: 1

Related Questions