Skip to content

Commit 0d98b0c

Browse files
Address PR feedback
1 parent 9bc35cf commit 0d98b0c

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

exercises-sprint5/enums.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,28 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]
7373
# Get user input as strings first (raw input)
7474
name = input("Enter your name: ")
7575
age_str = input("Enter your age: ")
76-
os_str = input("Enter preferred OS: ")
76+
print("Available operating systems: Ubuntu, macOS, Arch Linux")
77+
os_str = input("Enter your preferred OS (Ubuntu, macOS, or Arch Linux): ")
7778

7879
# --------------------------------------------------------------------
7980
# INPUT VALIDATION AND CONVERSION
8081
# --------------------------------------------------------------------
8182

8283
# Convert age from string to integer with error handling
8384
# Output to stderr as per requirements, exit with non-zero code
84-
try:
85-
age = int(age_str)
86-
except ValueError:
87-
88-
print(f"Error: {age_str} is not a valid age", file=sys.stderr)
89-
sys.exit(1)
85+
while True:
86+
age_str = input("Enter your age: ")
87+
try:
88+
age = int(age_str)
89+
break
90+
except ValueError:
91+
print(f"Error: {age_str} is not a valid age. Please enter a number.")
9092

9193
# Convert OS string to enum with error handling
9294
try:
9395
os = OperatingSystem(os_str)
9496
except ValueError:
95-
print(f"Error: '{os_str}' is not a valid OS. Choose: Ubuntu, macOS, Arch Linux", file=sys.stderr)
97+
print(f"Error: '{os_str}' is not a valid OS. Valid options are: Ubuntu, macOS, Arch Linux", file=sys.stderr)
9698
sys.exit(1)
9799

98100

exercises-sprint5/generics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ class Person:
1616

1717
imran = Person(name="Imran",age=50, children=[fatma, aisha])
1818

19-
def print_family_tree(person: Person) -> None:
20-
print(person.name)
19+
def print_family_tree(person: Person, level: int = 0) -> None:
20+
indent = " " * level
21+
print(f"{indent}{person.name} ({person.age})")
2122
for child in person.children:
22-
print(f"- {child.name} ({child.age})")
23+
print_family_tree(child, level + 1)
24+
2325

2426
print_family_tree(imran)
2527

exercises-sprint5/person2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class Person:
1010
name: str
1111
date_of_birth: date
1212
preferred_operating_system: str
13-
14-
13+
1514
def is_adult(self) -> bool:
1615
today_date = date.today().year
1716
birth_year = self.date_of_birth.year

0 commit comments

Comments
 (0)