Python Forum

Full Version: using 'while loop' output going into infinite loop...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.")
Did you mean to use "if" instead of "while"?
Actually, you're comparing something that's equal to itself. You can just remove the loop.