Python Forum
using 'while loop' output going into infinite loop...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using 'while loop' output going into infinite loop...
#1
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.")
Reply
#2
Did you mean to use "if" instead of "while"?
Reply
#3
Actually, you're comparing something that's equal to itself. You can just remove the loop.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Infinite Loop with my code TheGrado 9 166 Mar-24-2026, 06:16 AM
Last Post: Pedroski55
  Using a For Loop to subtract numbers from an input function. Anunderling 9 2,819 Sep-22-2025, 08:56 PM
Last Post: deanhystad
  Problem with For loop indentation Mormolyce 10 3,116 Sep-03-2025, 03:55 AM
Last Post: DeaD_EyE
  Break within an if statement inside a while loop not working Python_more_on 2 1,893 Sep-03-2025, 12:55 AM
Last Post: Pedroski55
  Error loop with Chatgpt sportak12 1 3,398 Aug-26-2025, 08:11 AM
Last Post: python_developer
  Returning data on button click by buttons created by a loop bradells 3 1,311 Apr-23-2025, 03:01 PM
Last Post: Pedroski55
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 4,649 Apr-01-2025, 12:46 PM
Last Post: Frankd
  really new to python want to know how to do a loop pentopdmj 6 2,647 Mar-09-2025, 12:59 PM
Last Post: snippsat
  knowing for loop position in a list medic5678 4 1,568 Jan-31-2025, 04:19 PM
Last Post: perfringo
  Run this once instead of a loop, do I need the 'calibration' steps? duckredbeard 2 1,358 Jan-28-2025, 04:55 PM
Last Post: duckredbeard

Forum Jump:

User Panel Messages

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