print("Welcome to OCR Theme Park!")
height=int(input("What is your height in centimetres?: "))
adult=("Are you riding with an adult?: ")
if height>150:
print("You are allowed to ride.")
else:
print("You are not allowed to ride.")
I need to make it so that the code can repeat until 8 people have been allowed to ride.
CodePudding user response:
Accomplish this using a while loop and a counter var.
counter = 0
while True:
print("Welcome to OCR Theme Park!")
height=int(input("What is your height in centimetres?: "))
adult=input("Are you riding with an adult?: ")
if height>150:
print("You are allowed to ride.")
counter =1
else:
print("You are not allowed to ride."
if counter == 8:
break
Your adult var also wasn’t taking user input.
CodePudding user response:
Since you don't know how many 'people' your app might 'meet,' (the difference between "the first eight people" and "until you have eight people who are above the minimum height"), you need to use a while loop.
while(something is true):
You'll also need a counter variable to know when you've hit your 8-person threshold.
num_people = 0
Here's one way of doing it:
print("Welcome to OCR Theme Park!")
num_people = 0 # counts number of people who are 'on' the ride
while(num_people < 8):
height=int(input("What is your height in centimetres?: "))
if height>150:
print("You are allowed to ride.")
num_people = 1
else:
print("You are not allowed to ride.")
I did not test this in python, I'll leave that to you. It looks like you'll need additional logic to determine if they are riding with an adult. I omitted that above. Hopefully it is enough to get you started in the right direction.
CodePudding user response:
you can do a counter for the number of adults so until 8 adults aren't in, the code won't continue.
and i also changed a little the code
adults = []
print("Welcome to OCR Theme Park!")
while len(adults) != 8:
height=int(input("What is your height in centimetres?: "))
if height>150:
print("You are allowed to ride.")
else:
adult=input("Are you riding with an adult?: ")
if adult == "no"
print("You are not allowed to ride.")
else:
adultname = input("what's his name? ")
if adultname in adults:
print("go on!")
continue
else:
print("He isn't here, you can come along later...")
