Skip to content

Commit ddb7be6

Browse files
Fix: enforce minimum age requirement in user prompt and improve output formatting
1 parent a09ea0a commit ddb7be6

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

prep-exercises/h_enums.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ def user_prompt() -> Person:
6363
raise ValueError("Name must contain only alphabetic characters.")
6464

6565
age = int(input("Please enter your age: "))
66-
if age <= 0:
67-
raise ValueError("Age must be positive.")
66+
minimum_age = 18
67+
if age < minimum_age:
68+
raise ValueError("Age must be 18 or over.")
69+
6870

6971
# define valid OS options
7072
valid_os = [os.value for os in OperatingSystem]
7173

72-
# dynamically display the os options
74+
# dynamically display the os options (no need for str type here as input always returns a string)
7375
preferred_os = input(f"Please enter correct operating system name, either {', '.join(valid_os)}: ").strip()
7476

7577
# validate the OS
@@ -97,7 +99,7 @@ def main() -> None:
9799
# get the counts of the laptops for an OS e.g. os_counts = {OperatingSystem.MACOS: 4,OperatingSystem.ARCH: 2,OperatingSystem.UBUNTU: 3}
98100
os_counts = Counter(laptop.operating_system for laptop in laptops)
99101

100-
print(f"{user_details.name}, there are {len(matching_laptops)} laptops available with your preferred operating system ({user_details.preferred_operating_systems.value}).")
102+
print(f"\n{user_details.name}, there are {len(matching_laptops)} laptops available with your preferred operating system ({user_details.preferred_operating_systems.value}).\n")
101103

102104
if matching_laptops:
103105
print("Matching laptops:")
@@ -113,10 +115,10 @@ def main() -> None:
113115
alternative_os = [(os, count) for os, count in os_counts.items() if count > user_os_count]
114116

115117
if alternative_os:
116-
print("However, there are more laptops available with the following operating systems:")
118+
print("\nHowever, there are more laptops available with the following operating systems:")
117119
for os, count in alternative_os:
118120
print(f"- {os.value}: {count} laptops")
119-
print("If you consider one of these options, you will have a greater chance of getting a laptop.")
121+
print("\nIf you consider one of these options, you will have a greater chance of getting a laptop.")
120122
else:
121123
print("Your preferred operating system has the most laptops available.")
122124

0 commit comments

Comments
 (0)