Add tasks
This commit is contained in:
parent
b31b0fcc56
commit
0919e6e884
21
Exercise 2/8 - Billettpriser og rabatter/8b.py
Normal file
21
Exercise 2/8 - Billettpriser og rabatter/8b.py
Normal file
@ -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,-')
|
35
Exercise 2/8 - Billettpriser og rabatter/8c.py
Normal file
35
Exercise 2/8 - Billettpriser og rabatter/8c.py
Normal file
@ -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,-')
|
Loading…
Reference in New Issue
Block a user