Python Forum
stock in while loop can someone help?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
stock in while loop can someone help?
#2
Your code includes conversion from message to int, so the error message you provided is no longer applicable. However the conversion causes another problem because the user cannot enter "quit" because that is not something that can be turned into an int.

You can test for quit before doing the conversion:
while True:
    message = input("what age you are")
    if message == "quit":
        break;
    ticket = int(message)
    if ticket <= 4:
        print("you can enter freely becuse your samell")
    elif ticket <= 13:
        print("the ticket will be for you 10$")
    else:
        print("the ticket will be for you 15$")
This is better, but still a very weak test. What if the user enters something that is not "quit" and isn't a number. What happens then?
Reply


Messages In This Thread
stock in while loop can someone help? - by yukhei - May-15-2020, 11:50 AM
RE: stock in while loop can someone help? - by deanhystad - May-15-2020, 12:42 PM

Forum Jump:

User Panel Messages

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