-
Notifications
You must be signed in to change notification settings - Fork 0
/
7 kyu Cost of my ride.py
51 lines (34 loc) · 1.63 KB
/
7 kyu Cost of my ride.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
https://www.codewars.com/kata/586430a5b3a675296a000395/train/python
This Kata is intended as a small challenge for my students
Create a function, called insurance(), that computes the cost of renting a car. The function takes 3 arguments: the age of the renter, the size of the car, and the number days for the rental. The function should return an integer number of the calculated total cost of the rental.
Age (integer) : There is a daily charge of $10 if the driver is under 25
Car Size (string) : There may be an additional daily charge based on the car size:
car size surcharge "economy" $0 "medium" $10 "full-size" $15
Rental Days (integer) : There is a base daily charge of $50 for renting a car. Simply multiply the one day cost by the number of days the car is rented in order to get the full cost.
Note: Negative rental days should return 0 cost. Any other car size NOT listed should come with a same surcharge as the "full-size", $15.
insurance(18, "medium", 7); // => 490
insurance(30,"full-size",30); // => 1950
insurance(21,"economy",-10); // => 0
insurance(42,"my custom car",7); // => 455
"""
def insurance(age, size, num_of_days):
if num_of_days < 0:
return 0
total = 0
if age < 25:
total += 10
if size == 'economy':
total += 0
elif size == 'medium':
total += 10
elif size == 'full-size':
total += 15
else:
total += 15
total = (num_of_days * (50 + total))
return total
print(insurance(18, "medium", 7), 490)
print(insurance(30, "full-size", 30), 1950)
print(insurance(21, "economy", -10), 0)
print(insurance(42, "my custom car", 7), 455)