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:
JavaScript
x
23
23
1
def main():
2
print("Your final price for Orchestra seats will be $",get_orchp())
3
print("Your final price for Center seats will be $",get_centerp())
4
def get_orchp():
5
ORCH_SEATS = 75
6
frontseats = float(input('Enter the number of Orchestra seats you want to purchase : '))
7
Finalorchp = ORCH_SEATS * frontseats
8
member = str(input('Are you a member of the local theater group? Enter y or n: '))
9
if member == 'y':
10
discount = 0.5
11
disc = Finalorchp * discount
12
Findiscorchp = Finalorchp - disc
13
elif member == 'n':
14
print('There is no discount for non-members')
15
return Finalorchp
16
return findiscorchp
17
def get_centerp():
18
CENTER_SEATS = 50
19
middleseats = float(input('Enter the number of Center Stage seats you want to purchase : '))
20
Finalcenterp = CENTER_SEATS * middleseats
21
return Finalcenterp
22
main()
23
Advertisement
Answer
This is how I would resolve all of your questions:
JavaScript
1
28
28
1
def main():
2
orchp = get_orchp()
3
centerp = get_centerp()
4
print(f"Your final price for Orchestra seats will be ${orchp}")
5
print(f"Your final price for Center seats will be ${centerp}")
6
print(f'Your final price for all tickets is {orchp + centerp}')
7
8
def get_orchp():
9
ORCH_SEATS = 75
10
frontseats = float(input('Enter the number of Orchestra seats you want to purchase : '))
11
Finalorchp = ORCH_SEATS * frontseats
12
member = str(input('Are you a member of the local theater group? Enter y or n: '))
13
if member == 'y':
14
Finalorchp *= .95
15
return Finalorchp
16
else:
17
print('There is no discount for non-members')
18
return Finalorchp
19
20
def get_centerp():
21
CENTER_SEATS = 50
22
middleseats = float(input('Enter the number of Center Stage seats you want to purchase : '))
23
Finalcenterp = CENTER_SEATS * middleseats
24
return Finalcenterp
25
26
main()
27
28
Please note these
- I change the location of the calls to your functions and set a variable to receive them
- I changed the prints for the final price to an f string to receive the variables from the functions
- Changed Finalorchp to the pythonic version of variable = variable * .95 right under the if member statement
- 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)
- Added another final price print with an f string to add the two variables that receive the 2 variables from the functions.