Skip to content
Advertisement

How to ask if a user is a member and if so, display their discounted price and how to add all values up? [closed]

I want to ask the user if they are members and if so, give them a 5% discount on the seats they have purchased, if they are not members, there is no discount. I also want to display that discounted price. Also, how would I go about adding up all the final prices and displaying those as well? I don’t know where to start with this, any help is appreciated, thanks. There may be some formatting issues, but here is my code:

def main():
 print("Your final price for Orchestra seats will be $",get_orchp())
 print("Your final price for Center seats will be $",get_centerp())
def get_orchp():
 ORCH_SEATS = 75
 frontseats = float(input('Enter the number of Orchestra seats you want to purchase : '))
 Finalorchp = ORCH_SEATS * frontseats
 member = str(input('Are you a member of the local theater group? Enter y or n: '))
 if member == 'y':
        discount = 0.5
        disc = Finalorchp * discount
        Findiscorchp = Finalorchp - disc
 elif member == 'n':
  print('There is no discount for non-members')
return Finalorchp
return findiscorchp
def get_centerp():
 CENTER_SEATS = 50
 middleseats = float(input('Enter the number of Center Stage seats you want to purchase : '))
 Finalcenterp = CENTER_SEATS * middleseats
 return Finalcenterp
main()

Advertisement

Answer

This is how I would resolve all of your questions:

def main():
    orchp = get_orchp()
    centerp = get_centerp()
    print(f"Your final price for Orchestra seats will be ${orchp}")
    print(f"Your final price for Center seats will be ${centerp}")
    print(f'Your final price for all tickets is {orchp + centerp}')
    
def get_orchp():
    ORCH_SEATS = 75
    frontseats = float(input('Enter the number of Orchestra seats you want to purchase : '))
    Finalorchp = ORCH_SEATS * frontseats
    member = str(input('Are you a member of the local theater group? Enter y or n: '))
    if member == 'y':
        Finalorchp *= .95
        return Finalorchp
    else:
        print('There is no discount for non-members')
        return Finalorchp

def get_centerp():
    CENTER_SEATS = 50
    middleseats = float(input('Enter the number of Center Stage seats you want to purchase : '))
    Finalcenterp = CENTER_SEATS * middleseats
    return Finalcenterp

main()

Please note these

  1. I change the location of the calls to your functions and set a variable to receive them
  2. I changed the prints for the final price to an f string to receive the variables from the functions
  3. Changed Finalorchp to the pythonic version of variable = variable * .95 right under the if member statement
  4. Changed the else statement in get_orchp to else in the event that the user doesn’t only put y or n (you could add onto this to have fault tolerance of if it isn’t y or n then do something else)
  5. Added another final price print with an f string to add the two variables that receive the 2 variables from the functions.
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement