TDT4109/Exercise 2/8 - Billettpriser og rabatter/8c.py

38 lines
942 B
Python

def boolInput(question):
while True:
try:
choice = input(question)
assert choice in ['J', 'j', 'N', 'n']
return choice in ['J','j']
except AssertionError:
print('Skriv in J eller N\n')
def miniPriceBranch():
choseMiniPrice = boolInput('Minipris 199,- kan ikke refunderes/endres\nØnskes dette (J/N)? ')
if choseMiniPrice:
print('Takk for pengene, god reise!')
else:
normalBranch()
def evalDiscountPercent():
age = int(input('Skriv inn din alder: '))
if age < 16:
return 50
elif age >= 60:
return 25
hasSpecialSocialStatus = boolInput('Er du student eller militær (J/N)?')
return 25 if hasSpecialSocialStatus else 0
def normalBranch():
discountPercent = evalDiscountPercent()
print(f'Prisen på biletten blir: {440 - 440 * discountPercent/100}')
daysToTrip = int(input('Dager til du skal reise? '))
if daysToTrip >= 14:
miniPriceBranch()
else:
normalBranch()