Jun-14-2017, 07:01 AM
Why won't this code work? It doesn't run through as it's meant to and fails to set the variables to what they are meant to be! The first example is "carers" being undefined when it should be 2/3.
import time
def people_check(seniors):
if seniors >= 10 and seniors <= 24:
carers = 2
elif seniors >= 25 and seniors <= 36:
carers = 3
else:
if seniors < 10:
print ("You can't have that few senior citizens on a trip, sorry! This program will now terminate.")
elif seniors > 36:
print ("You can't have that many senior citizens on a trip, sorry! This program will now terminate.")
time.sleep(3)
quit()
def money_calc(people):
if people >= 12 and people <= 16:
coach_price = 150.00
meal_price = 14.00
ticket_price = 21.00
elif people >=17 and people <= 26:
coach_price = 190.00
meal_price = 13.50
ticket_price = 20.00
else:
coach_price = 225.00
meal_price = 13.00
ticket_price = 19.00
def total_calc(coach_price, meal_price, ticket_price):
meal_split = (meal_price * carers) / seniors
ticket_split = (ticket_price * carers) / seniors
meal_ind_total = meal_price + meal_split
ticket_ind_total = ticket_price + ticket_split
total = coach_price + (meal_price * people) + (ticket_price * people)
ind_total = (coach_price / people) + meal_ind_total + ticket_ind_total
total = round(total, 2)
ind_total = round(ind_total, 2)
def full_code():
seniors = int(input("How many senior citizens will be going on the trip?"))
people_check(seniors)
people = seniors + carers
print ("There will be {0} carers and {1} people in total on the trip.".format(carers, people))
money_calc(people)
total_calc(coach_price, meal_price, ticket_price)
print ("The total cost of the trip will be ${0} and the cost per senior citizen will be ${1}.".format(total, ind_total))
check = str(input("Would you like to do a calculation?"))
if check == "Yes" or check == "yes":
full_code()
elif check =="No" or check == "no":
quit()
else:
print ("Sorry, that is not accepted, this program will now terminate.")
time.sleep(3)
quit()
