diff --git a/Exercise 2/8 - Billettpriser og rabatter/8b.py b/Exercise 2/8 - Billettpriser og rabatter/8b.py new file mode 100644 index 0000000..91e92b2 --- /dev/null +++ b/Exercise 2/8 - Billettpriser og rabatter/8b.py @@ -0,0 +1,21 @@ + +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 discountBranch(): + choseDiscount = boolInput('Minipris 199,- kan ikke refunderes/endres\nØnskes dette (J/N)? ') + print('Takk for pengene, god reise!' if choseDiscount else 'Da tilbyr vi fullpris: 440,-') + + +daysToTrip = int(input('Dager til du skal reise? ')) + +if daysToTrip >= 14: + discountBranch() +else: + print('For sent for minipris; fullpris 440,-') \ No newline at end of file diff --git a/Exercise 2/8 - Billettpriser og rabatter/8c.py b/Exercise 2/8 - Billettpriser og rabatter/8c.py new file mode 100644 index 0000000..fc3d2ff --- /dev/null +++ b/Exercise 2/8 - Billettpriser og rabatter/8c.py @@ -0,0 +1,35 @@ + +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 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 discountBranch(): + choseDiscount = boolInput('Minipris 199,- kan ikke refunderes/endres\nØnskes dette (J/N)? ') + if choseDiscount: + discountPercent = evalDiscountPercent() + print(f'Prisen på biletten blir: {440 - 440 * discountPercent/100}') + else: + print('Da tilbyr vi fullpris: 440,-') + + +daysToTrip = int(input('Dager til du skal reise? ')) + +if daysToTrip >= 14: + discountBranch() +else: + print('For sent for minipris; fullpris 440,-') \ No newline at end of file