This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flight.py
82 lines (65 loc) · 2.19 KB
/
flight.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import arrow
class Flight:
'''
this class represents a flight
args:
none
kwargs:
example
{
'source': 'DPS',
'destination': 'BWN',
'departure': '2017-02-11T22:10:00',
'arrival': '2017-02-12T00:35:00',
'flight_number': 'PV197',
'price': 50,
'bags_allowed': 1,
'bag_price': 30
}
'''
def __init__(self, **kwargs):
self._source = kwargs['source']
self._destination = kwargs['destination']
self._departure = arrow.get(kwargs['departure'])
self._arrival = arrow.get(kwargs['arrival'])
self._flight_number = kwargs['flight_number']
self._price = kwargs['price']
self._bags_allowed = kwargs['bags_allowed']
self._bag_price = kwargs['bag_price']
def allowed_bags(self, amount_bags: int)->bool:
'''
arg:
amount_bags: amount of bags that a passager want to bring
return:
true or false if possible
'''
if amount_bags < 0:
raise ValueError('You can not bring a negatief amount of bags {}'.format(amount_bags))
else:
if amount_bags <= self._bags_allowed:
return True
else:
return False
def total_price(self, total_bags=0)->int:
'''
calculates the total price of the fligt by the given bags taken on the flight
arg:
total_bages : the total amount of bags taken on the flight
return:
the total price of the flight
'''
if not self.allowed_bags(total_bags):
raise ValueError('the total bags {} are more than allowed {}'.format(total_bags, self._bags_allowed))
return self._price + total_bags * self._bag_price
def departure_destination(self):
return self._source
def arrival_destination(self):
return self._destination
def departure_time(self):
return self._departure
def arrival_time(self):
return self._arrival
def max_allowed_bags(self):
return self._bags_allowed
def info_flight(self):
return self._flight_number