Skip to content

Commit 579f83d

Browse files
committed
Format code with Black
1 parent e79d308 commit 579f83d

8 files changed

Lines changed: 157 additions & 64 deletions

File tree

sprint5-prep/prep2-exercise.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
def open_account(balances: dict[str,int], name : str, amount:int) -> None:
1+
def open_account(balances: dict[str, int], name: str, amount: int) -> None:
22
balances[name] = amount
33

4-
def sum_balances(accounts : dict[str,int]) -> int:
4+
5+
def sum_balances(accounts: dict[str, int]) -> int:
56
total = 0
67
for name, pence in accounts.items():
78
print(f"{name} had balance {pence}")
89
total += pence
910
return total
1011

11-
def format_pence_as_string(total_pence :int) -> str:
12+
13+
def format_pence_as_string(total_pence: int) -> str:
1214
if total_pence < 100:
1315
return f"{total_pence}p"
1416
pounds = int(total_pence / 100)
1517
pence = total_pence % 100
1618
return f"£{pounds}.{pence:02d}"
1719

20+
1821
balances = {
1922
"Sima": 700,
2023
"Linn": 545,
2124
"Georg": 831,
2225
}
2326

24-
open_account(balances,"Tobi", 913)
25-
open_account(balances,"Olya", 713)
27+
open_account(balances, "Tobi", 913)
28+
open_account(balances, "Olya", 713)
2629

2730
total_pence = sum_balances(balances)
2831
total_string = format_pence_as_string(total_pence)
2932

30-
print(f"The bank accounts total {total_string}")
33+
print(f"The bank accounts total {total_string}")

sprint5-prep/prep3-exercise.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ def __init__(self, name: str, age: int, preferred_operating_system: str):
44
self.age = age
55
self.preferred_operating_system = preferred_operating_system
66

7+
78
imran = Person("Imran", 22, "Ubuntu")
89
print(imran.name)
910

1011

1112
eliza = Person("Eliza", 34, "Arch Linux")
1213
print(eliza.name)
1314

15+
1416
def is_adult(person: Person) -> bool:
1517
return person.age >= 18
1618

19+
1720
print(is_adult(imran))
1821

19-
def is_from_UK(person:Person) -> bool :
20-
return person.country=="UK"
21-
print(is_from_UK(eliza))
22+
23+
def is_from_UK(person: Person) -> bool:
24+
return person.country == "UK"
25+
26+
27+
print(is_from_UK(eliza))

sprint5-prep/prep4-exercise.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import datetime
2+
3+
24
class Person:
3-
def __init__(self, name: str, date_of_birth : datetime.date, preferred_operating_system: str):
5+
def __init__(
6+
self, name: str, date_of_birth: datetime.date, preferred_operating_system: str
7+
):
48
self.name = name
5-
self.date_of_birth =date_of_birth
9+
self.date_of_birth = date_of_birth
610
self.preferred_operating_system = preferred_operating_system
11+
712
def is_adult(self):
8-
today=datetime.date.today()
9-
age=today.year-self.date_of_birth.year
13+
today = datetime.date.today()
14+
age = today.year - self.date_of_birth.year
1015
print(age)
1116
return age >= 18
1217

13-
imran = Person("Imran", datetime.date(1998,4,3), "Ubuntu")
18+
19+
imran = Person("Imran", datetime.date(1998, 4, 3), "Ubuntu")
1420
print(imran.is_adult())
15-
eliza = Person("Eliza",datetime.date(2013,3,17), "Arch Linux")
16-
print(eliza.is_adult())
21+
eliza = Person("Eliza", datetime.date(2013, 3, 17), "Arch Linux")
22+
print(eliza.is_adult())

sprint5-prep/prep5-exercise.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
from dataclasses import dataclass
22
import datetime
3+
4+
35
@dataclass(frozen=True)
46
class Person:
57
name: str
68
date_of_birth: datetime.date
79
preferred_operating_system: str
8-
def is_adult(self) -> bool :
9-
today=datetime.date.today()
10-
age=today.year-self.date_of_birth.year
11-
if(today.month,today.day)<(self.date_of_birth.month,self.date_of_birth.day) :
12-
age -=1
13-
return age>=18
14-
imran = Person("Imran", datetime.date(2007,12,16), "Ubuntu")
15-
print(imran)
16-
print(imran.is_adult())
1710

11+
def is_adult(self) -> bool:
12+
today = datetime.date.today()
13+
age = today.year - self.date_of_birth.year
14+
if (today.month, today.day) < (
15+
self.date_of_birth.month,
16+
self.date_of_birth.day,
17+
):
18+
age -= 1
19+
return age >= 18
20+
21+
22+
imran = Person("Imran", datetime.date(2007, 12, 16), "Ubuntu")
23+
print(imran)
24+
print(imran.is_adult())

sprint5-prep/prep6-exercise.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
from dataclasses import dataclass
22
from typing import List
33

4+
45
@dataclass(frozen=True)
56
class Person:
67
name: str
7-
age :int
8+
age: int
89
children: List["Person"]
9-
fatma = Person(name="Fatma",age=8, children=[])
10-
aisha = Person(name="Aisha",age=12, children=[])
1110

12-
imran = Person(name="Imran",age=40, children=[fatma, aisha])
11+
12+
fatma = Person(name="Fatma", age=8, children=[])
13+
aisha = Person(name="Aisha", age=12, children=[])
14+
15+
imran = Person(name="Imran", age=40, children=[fatma, aisha])
16+
1317

1418
def print_family_tree(person: Person) -> None:
1519
print(person.name)
1620
for child in person.children:
1721
print(f"- {child.name} ({child.age})")
1822

19-
print_family_tree(imran)
23+
24+
print_family_tree(imran)

sprint5-prep/prep7-exercise.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22
from typing import List
33

4+
45
@dataclass(frozen=True)
56
class Person:
67
name: str
@@ -31,12 +32,36 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]
3132
]
3233

3334
laptops = [
34-
Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"),
35-
Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"),
36-
Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"),
37-
Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"),
35+
Laptop(
36+
id=1,
37+
manufacturer="Dell",
38+
model="XPS",
39+
screen_size_in_inches=13,
40+
operating_system="Arch Linux",
41+
),
42+
Laptop(
43+
id=2,
44+
manufacturer="Dell",
45+
model="XPS",
46+
screen_size_in_inches=15,
47+
operating_system="Ubuntu",
48+
),
49+
Laptop(
50+
id=3,
51+
manufacturer="Dell",
52+
model="XPS",
53+
screen_size_in_inches=15,
54+
operating_system="ubuntu",
55+
),
56+
Laptop(
57+
id=4,
58+
manufacturer="Apple",
59+
model="macBook",
60+
screen_size_in_inches=13,
61+
operating_system="macOS",
62+
),
3863
]
3964

4065
for person in people:
4166
possible_laptops = find_possible_laptops(laptops, person)
42-
print(f"Possible laptops for {person.name}: {possible_laptops}")
67+
print(f"Possible laptops for {person.name}: {possible_laptops}")

sprint5-prep/prep8-exercise.py

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import sys
55
from collections import Counter
66

7+
78
class OperatingSystem(Enum):
89
MACOS = "macOS"
910
ARCH = "Arch Linux"
1011
UBUNTU = "Ubuntu"
1112

13+
1214
@dataclass(frozen=True)
1315
class Person:
1416
name: str
@@ -24,28 +26,32 @@ class Laptop:
2426
screen_size_in_inches: float
2527
operating_system: OperatingSystem
2628

27-
name=input("Insert your name :")
28-
if len(name)==0 :
29+
30+
name = input("Insert your name :")
31+
if len(name) == 0:
2932
print("Name cannot be empty!", file=sys.stderr)
3033
exit(1)
31-
elif len(name)>50 :
32-
print("Name is too long!", file=sys.stderr)
34+
elif len(name) > 50:
35+
print("Name is too long!", file=sys.stderr)
3336
exit(1)
34-
try :
35-
age=int(input("Insert your age :"))
36-
if age<18 or age>100 :
37+
try:
38+
age = int(input("Insert your age :"))
39+
if age < 18 or age > 100:
3740
raise ValueError("Age out of range")
38-
except ValueError as e :
41+
except ValueError as e:
3942
print(f"Invalid age: {e}", file=sys.stderr)
4043
sys.exit(1)
41-
preferred_os=input("Insert your preferred_operating_system(macOS,Arch Linux,Ubuntu) :")
42-
try :
43-
preferred_operating_system=OperatingSystem(preferred_os)
44+
preferred_os = input(
45+
"Insert your preferred_operating_system(macOS,Arch Linux,Ubuntu) :"
46+
)
47+
try:
48+
preferred_operating_system = OperatingSystem(preferred_os)
4449
except ValueError:
45-
print("error in os name",file=sys.stderr)
50+
print("error in os name", file=sys.stderr)
4651
sys.exit(1)
4752

48-
person=Person(name,age,preferred_operating_system)
53+
person = Person(name, age, preferred_operating_system)
54+
4955

5056
def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]:
5157
possible_laptops = []
@@ -56,24 +62,58 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]
5662

5763

5864
laptops = [
59-
Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH),
60-
Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU),
61-
Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU),
62-
Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system=OperatingSystem.MACOS),
63-
Laptop(id=5, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH),
65+
Laptop(
66+
id=1,
67+
manufacturer="Dell",
68+
model="XPS",
69+
screen_size_in_inches=13,
70+
operating_system=OperatingSystem.ARCH,
71+
),
72+
Laptop(
73+
id=2,
74+
manufacturer="Dell",
75+
model="XPS",
76+
screen_size_in_inches=15,
77+
operating_system=OperatingSystem.UBUNTU,
78+
),
79+
Laptop(
80+
id=3,
81+
manufacturer="Dell",
82+
model="XPS",
83+
screen_size_in_inches=15,
84+
operating_system=OperatingSystem.UBUNTU,
85+
),
86+
Laptop(
87+
id=4,
88+
manufacturer="Apple",
89+
model="macBook",
90+
screen_size_in_inches=13,
91+
operating_system=OperatingSystem.MACOS,
92+
),
93+
Laptop(
94+
id=5,
95+
manufacturer="Dell",
96+
model="XPS",
97+
screen_size_in_inches=13,
98+
operating_system=OperatingSystem.ARCH,
99+
),
64100
]
65101

66-
os_count=Counter(laptop.operating_system for laptop in laptops)
67-
max_count=max(os_count.values())
102+
os_count = Counter(laptop.operating_system for laptop in laptops)
103+
max_count = max(os_count.values())
68104
print(max_count)
69-
most_available_os=[]
70-
for os in os_count :
71-
count=os_count[os]
72-
if count==max_count :
73-
most_available_os.append(os.value)
105+
most_available_os = []
106+
for os in os_count:
107+
count = os_count[os]
108+
if count == max_count:
109+
most_available_os.append(os.value)
74110
print(most_available_os)
75111
possible_laptops = find_possible_laptops(laptops, person)
76-
print(f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}")
112+
print(
113+
f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}"
114+
)
77115

78-
if len(possible_laptops)<max_count :
79-
print(f"Note: If you are willing to accept : {" or ".join(most_available_os)}, you are more likely to get a laptop.")
116+
if len(possible_laptops) < max_count:
117+
print(
118+
f"Note: If you are willing to accept : {" or ".join(most_available_os)}, you are more likely to get a laptop."
119+
)

sprint5-prep/prep9-exercise.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def get_full_name(self) -> str:
2222
suffix = f" (née {self.previous_last_names[0]})"
2323
return f"{self.first_name} {self.last_name}{suffix}"
2424

25+
2526
person1 = Child("Elizaveta", "Alekseeva")
2627
print(person1.get_name())
2728
print(person1.get_full_name())
@@ -34,4 +35,4 @@ def get_full_name(self) -> str:
3435
# print(person2.get_full_name())
3536
# person2.change_last_name("Tyurina")
3637
print(person2.get_name())
37-
# print(person2.get_full_name())
38+
# print(person2.get_full_name())

0 commit comments

Comments
 (0)