-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrail.py
49 lines (40 loc) · 1.05 KB
/
trail.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 4 14:08:32 2022
@author: parth
"""
x = [
'a',
'b',
{
'foo':1,
'bar':
{'x' : 10,
'y': 20,
'z':30},
'baz':3},
'c',
'd'
]
class Airplane:
def __init__(self, manufacturer:str, model:str):
self.manufacturer = manufacturer
self.model = model
self.engine_on = False
self.flying = False
print(f'Created a new {self.manufacturer} {self.model}airplane')
def __repr__(self):
return f'{self.manufacturer}{self.model}'
@classmethod
def from_string(cls, name:str):
import re
m = re.search(r"([a-zA-z]+)(\d+)",name)
if m:
return cls(m.group(1), m.group(2))
raise Exception("Invalid")
class Hangar:
def __init__(self, airplanes:list):
self.airplanes = [Airplane.from_string(i) for i in airplanes]
def count(self):
return len(self.airplanes)