Skip to content

Commit ef11757

Browse files
authored
create theatre.py
1 parent 5089036 commit ef11757

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

Assessment/Wk2/helpers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ def get_float(input_prompt, min_val=float(0.01), max_val=float(100.00)):
3939
print ( f"Invalid '{input_prompt}' value entered '{get_val}'" )
4040
finally:
4141
return return_value
42+
43+
## function to get an Y/N with error checking
44+
def get_y_n ( input_prompt ):
45+
return_value=""
46+
var_val = "Z"
47+
48+
try:
49+
while not ( var_val == "Y" or var_val == "N" ) :
50+
var_val=input(input_prompt + f" (Y/N) ").upper()
51+
52+
## exit if select 0
53+
if var_val=='':
54+
break
55+
56+
return_value=var_val
57+
except:
58+
print ( f"Invalid '{input_prompt}' value entered '" + var_val + "'" )
59+
finally:
60+
return return_value
61+

Assessment/Wk4/theatre.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# calculate ticket costs for theatre bookings
2+
3+
# helpers
4+
5+
## function to get an integer with error checking
6+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
7+
return_value=int(0)
8+
int_val=int(-1)
9+
10+
try:
11+
while not ((int_val >= min_val and int_val <= max_val)) :
12+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
13+
int_val=int(get_val)
14+
15+
## exit if select 0
16+
if int_val==0:
17+
break
18+
19+
return_value=int_val
20+
except:
21+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
22+
finally:
23+
return return_value
24+
25+
## function to get an Y/N with error checking
26+
def get_y_n ( input_prompt ):
27+
return_value=""
28+
var_val = "Z"
29+
30+
try:
31+
while not ( var_val == "Y" or var_val == "N" ) :
32+
var_val=input(input_prompt + f" (Y/N) ").upper()
33+
34+
## exit if select 0
35+
if var_val=='':
36+
break
37+
38+
return_value=var_val
39+
except:
40+
print ( f"Invalid '{input_prompt}' value entered '" + var_val + "'" )
41+
finally:
42+
return return_value
43+
44+
45+
46+
# inits
47+
costs = { 'Adult' : 10.50 , 'Child' : 7.30 , 'Conc' : 8.40 }
48+
num_kids_for_free_adult = 10
49+
50+
discount = { 'minimum_spend': float(100.00), 'discount' : int(10) }
51+
52+
the_p_n_p_cost = float(2.34)
53+
54+
# welcome
55+
print ( 'Thank you for shopping at TicketMistress' )
56+
print ( '=' * 40 )
57+
58+
# get values
59+
num_in_party = get_int( "Please enter the number of tickets required: " , 1 , 150 )
60+
num_adults = get_int( "How many full price adults? " , 1 , num_in_party)
61+
num_conc = get_int( "How many concessions? ", 0, (num_in_party - num_adults))
62+
is_collection = get_y_n( "Will you be collecting the tickets? " )
63+
64+
# calcs
65+
num_kids=num_in_party-num_adults-num_conc
66+
num_free_adults= int( num_kids / num_kids_for_free_adult )
67+
68+
# can't give away more seats than you've got!
69+
if num_free_adults > num_adults: num_free_adults=num_adults
70+
71+
# calc how many are paying
72+
num_paying_adults=num_adults-num_free_adults
73+
74+
ticket_values={"Adult": 0, "Conc": 0 , "Child": 0}
75+
ticket_values["Adult"] = num_paying_adults * costs["Adult"]
76+
ticket_values["Conc"] = num_conc * costs["Conc"]
77+
ticket_values["Child"] = num_kids * costs["Child"]
78+
79+
ttl_bill_pre_discount = ( ticket_values["Adult"] ) + \
80+
( ticket_values["Conc"] ) + \
81+
( ticket_values["Child"] )
82+
83+
# calculate discount
84+
discount_percentage = 0
85+
bill_discount = 0
86+
if ttl_bill_pre_discount > discount["minimum_spend"] :
87+
discount_percentage=discount["discount"]
88+
bill_discount = ttl_bill_pre_discount * ( discount_percentage / 100 )
89+
90+
# calculate delivery
91+
92+
if is_collection == "Y" :
93+
p_n_p_cost=0
94+
else :
95+
p_n_p_cost=the_p_n_p_cost
96+
97+
bill_total=ttl_bill_pre_discount - bill_discount + p_n_p_cost
98+
99+
# output bill
100+
print ( )
101+
print ( "The Sandford Paladium")
102+
print ( "*" * 21 )
103+
print ()
104+
105+
print ( f'{num_in_party} Tickets for Snakes! The Musical' )
106+
print ( '-' * 35 )
107+
if is_collection == "Y" :
108+
print ( "*" * 9, " COLLECTION ", "*" * 9 )
109+
print ( '-' * 35 )
110+
print ( f'{num_adults:3} {"Adult":12} ' )
111+
if num_paying_adults > 0 : print ( ' ' * 12 , f'{num_paying_adults:3} @ £{costs["Adult"]:5.2f} = £{ ticket_values["Adult"]:7.2f} ')
112+
if num_free_adults > 0 : print ( ' ' * 12 , f'{num_free_adults:3} @ £{0:5.2f} = £{0:7.2f} ')
113+
if num_conc > 0 : print ( f'{num_conc:3} {"Concession":12} @ £{costs["Conc"]:5.2f} = £{ ticket_values["Conc"]:7.2f} ')
114+
if num_kids > 0 : print ( f'{num_kids:3} {"Child":12} @ £{costs["Child"]:5.2f} = £{ ticket_values["Child"]:7.2f} ')
115+
print ( ' ' * 27, '=' * 8 )
116+
117+
if discount_percentage > 0 :
118+
print ( ' ' * 9 , f'{"Sub Total":17} £{ttl_bill_pre_discount:7.2f}' )
119+
print ( ' ' * 9 , f'{"Discount":17} £{bill_discount:7.2f}' )
120+
print ( ' ' * 27, '-' * 8 )
121+
122+
if p_n_p_cost > 0 :
123+
print ( ' ' * 9 , f'{"Postage":17} £{p_n_p_cost:7.2f}' )
124+
print ( ' ' * 27, '-' * 8 )
125+
126+
print ( ' ' * 9 , f'{"Total":17} £{bill_total:7.2f}' )
127+
print ( ' ' * 27, '=' * 8 )

0 commit comments

Comments
 (0)