1

My input in my if statement is not working. I am using Python3 and the problem is at the first if statement in the defined function.

import random

random1 = random.randint(1, 11)
random2 = random.randint(1, 11)
correct = random1 * random2
list_of_correct = []
list_of_wrong = []


def ex():
    proceed = input("Proceed?: ")
    if proceed.lower == "yes":
        ans = input("What is " + str(random1) + " * " + str(random2) + "?: ")
        if int(ans) == correct:
            print("Correct!")
            list_of_correct.append(str(random1 + ":" + str(random2) + ":" + str(ans)))
            print(ex())
        else:
            print("Incorrect!")
            list_of_wrong.append(str(random1) + ":" + str(random2) + ":" + str(ans))
    elif proceed.lower == "mfm":
        print(list_of_correct)
        print(list_of_wrong)


print(ex())
0

2 Answers 2

4

You compare a function proceed.lower against a string 'yes' - they are never the same.

You need to call the function:

if proceed.lower() == "yes":

to convert your input to lower case for your comparison.

print("".lower) # <built-in method lower of str object at 0x7fc134277508>
Sign up to request clarification or add additional context in comments.

Comments

0

Fixed code

import random

random1 = random.randint(1, 11)
random2 = random.randint(1, 11)
correct = random1 * random2
list_of_correct = []
list_of_wrong = []


def ex():
    proceed = input("Proceed?: ")
    if proceed.lower() == "yes":
        ans = input("What is " + str(random1) + " * " + str(random2) + "?: ")
        if int(ans) == correct:
            print("Correct!")
            list_of_correct.append(str(random1 + ":" + str(random2) + ":" + str(ans)))
            print(ex())
        else:
            print("Incorrect!")
            list_of_wrong.append(str(random1) + ":" + str(random2) + ":" + str(ans))
    elif proceed.lower() == "mfm":
        print(list_of_correct)
        print(list_of_wrong)


print(ex())

1 Comment

Updated a typo. @wjandrea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.