-1

The question is "Ask user to enter age, Check if age entered is > 0. if age less than 12 ticket price is 12 dollars otherwise the ticket price is 18 dollars"

def main() :
    n = int(input("Insert your age : ")) #asking for users age
    while True : # checking if users age is more than 0
        if n > 0 :
            break
    return n
    if price_checker(n) :
        print("Price is 12 dollars")
    else :
        print("Price is 18 dollars")
    
def price_checker(x) :
    if x < 12 :
        return True
    else :
        return False
    
main()

When i print it the only code executed was "insert your age : " i've tried a few ways to fix it but it just lead to more confusion

  • If the age is negative it's impossible to change `n` so the loop will run forever, and the rest of the program will never start – mousetail Nov 30 '22 at 14:59
  • 1
    Why do you have `return n` in the middle of the function? Everything after it can't run... – Tomerikoo Nov 30 '22 at 14:59

1 Answers1

0

Just check if the number is less than or equal to 0 instead of a while loop

def main() :
    n = int(input("Insert your age : ")) #asking for users age
    if n <= 0:
        print("Please enter an age greater than 0")
    elif price_checker(n) :
        print("Price is 12 dollars")
    else :
        print("Price is 18 dollars")
    
def price_checker(x) :
    if x < 12 :
        return True
    else :
        return False
    
main()
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34