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
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 1,965 Apr-01-2025, 12:46 PM
Last Post: Frankd
  really new to python want to know how to do a loop pentopdmj 6 1,508 Mar-09-2025, 12:59 PM
Last Post: snippsat
  knowing for loop position in a list medic5678 4 659 Jan-31-2025, 04:19 PM
Last Post: perfringo
  Run this once instead of a loop, do I need the 'calibration' steps? duckredbeard 2 707 Jan-28-2025, 04:55 PM
Last Post: duckredbeard
  Error loop with Chatgpt sportak12 0 481 Jan-14-2025, 12:04 PM
Last Post: sportak12
  How to convert while loop to for loop in my code? tatahuft 4 780 Dec-21-2024, 07:59 AM
Last Post: snippsat
  How to get keep information in a loop ginod 4 852 Dec-11-2024, 01:32 AM
Last Post: deanhystad
  Regarding The For Loop Hudjefa 5 1,426 Nov-15-2024, 01:02 PM
Last Post: deanhystad
  For Loop beginner agoldav 2 689 Nov-05-2024, 12:51 AM
Last Post: agoldav
  A question about 'Event loop is closed' fc5igm 3 4,965 Oct-01-2024, 09:12 AM
Last Post: skdaro

Forum Jump:

User Panel Messages

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