Python Forum

Full Version: Am I dumb?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am relatively new to python, and I thought I understood the basics of it already, but for some reason, this one block of code is giving me so many problems. I cannot find the problem with this code, as it just keeps looping for seemingly no reason. What am I doing wrong here? I know this code can be optimized by the way, it was optimized but after it kept looping I thought I would take it back to the basics and that would fix it, but I was wrong.



user_choice = ""
run_loop = "run"

while run_loop == "run":
    print()
    
    if user_choice.lower == "option 1":
        run_loop = "off"
    elif user_choice.lower == "option 2":
        run_loop = "off"
    elif user_choice.lower == "option 3":
        run_loop = "off"
    elif user_choice.lower == "option 4":
        run_loop = "off"
    elif user_choice.lower == "option 5":
        run_loop = "off"
    else:
        print("Here are your options:")
        user_choice = input("Option 1, Option 2, Option 3, Option 4, or Option 5: ")
Use lower() instead of lower.
>>> s = "Hello"
>>> s.lower
<built-in method lower of str object at 0x7f9943587830>
>>> s.lower()
'hello'
Next time you are stupid add a print statement to your code.
...
    else:
        print("Here are your options:")
        user_choice = input("Option 1, Option 2, Option 3, Option 4, or Option 5: ")
    print(user_choice.lower)
Output:
Option 1, Option 2, Option 3, Option 4, or Option 5: 7 <built-in method lower of str object at 0x0000015A2659FBB0>
Then you would wonder "Why is it printing that instead of 7?" This gives you something new to feel stupid about, but eventually you figure it out. You go read about "lower()" and notice the examples have parenthesis following lower. Then you read that the parenthesis are how you tell Python to call a function. Now you are less stupid and the next problem doesn't take so long to solve.

Been there. Done that.