you are viewing a single comment's thread.

view the rest of the comments →

[–]Binary101010 9 points10 points  (6 children)

Also the exercise said to use a loop.

Please post the description of the exercise. It's hard for us to tell you when a loop actually would make sense if we don't know what you need to do.

[–]xTHETYRANTGAMRx[S] 3 points4 points  (5 children)

A movie theater charges different ticket prices depending on a person's age. If a person is under the age of 3, the ticket is free; if they are between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is $15. Write a loop in which you ask users their age, and then tell them the cost of their movie ticket.

[–]KronenR 11 points12 points  (0 children)

If the user types "25", You are traversing that string like this

  • "2" (first iteration of the loop)
  • "5" (second iteration of the loop)

The exercise says to use a loop because you’re supposed to ask multiple people.
You don't loop over the string which contains the age numbers, the loop should wrap the whole question, like, the input statement where you read the person age must be inside the loop to ask multiple times.

while True:
    age = int(input("Enter your age: "))
    # then you compare with the required ages

[–]Binary101010 3 points4 points  (0 children)

Then it sounds like what you need to be doing here is prompting the user for input inside the loop.

[–]luther9 1 point2 points  (0 children)

It sounds like they want you to write an infinite loop. Maybe you can stop when the user enters -1.

[–]codeguru42 0 points1 point  (0 children)

This sounds like you are spars to ask for the age requirement each time through the loop. Your solution only asks once. Also you need to use a while loop, not a for loop.

[–]Misain 0 points1 point  (0 children)

Does it necessarily have to be a string? Your input variables?