Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am I dumb?
#1
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: ")
Reply
#2
Use lower() instead of lower.
>>> s = "Hello"
>>> s.lower
<built-in method lower of str object at 0x7f9943587830>
>>> s.lower()
'hello'
Reply
#3
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.
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dumb newbie question JonEdward 5 3,282 Jul-22-2020, 10:06 PM
Last Post: snippsat
  Simple script writted by a dumb dude, myself mm14ag 2 2,760 Apr-28-2018, 11:48 AM
Last Post: mm14ag

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020