Python Forum
using 'while loop' output going into infinite loop... - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: using 'while loop' output going into infinite loop... (/thread-30112.html)



using 'while loop' output going into infinite loop... - amitkb - Oct-05-2020

I am learning while loop. Below code is going into infinite loop when displaying the output. Please help.


prompt = input("Please share your age. I will tell you the price: ")

age = int(prompt)
while age == int(prompt):
    if age < 3:
        print("You are free to go!")
    elif age <=12:
        print("You have to pay $10.")
    else:
        print("You have to pay $15.")



RE: using 'while loop' output going into infinite loop... - micseydel - Oct-05-2020

Did you mean to use "if" instead of "while"?


RE: using 'while loop' output going into infinite loop... - micseydel - Oct-05-2020

Actually, you're comparing something that's equal to itself. You can just remove the loop.