-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
29 lines (23 loc) · 786 Bytes
/
hello.py
File metadata and controls
29 lines (23 loc) · 786 Bytes
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
from generals import is_string, is_valid_number
def ask_name() -> str:
"""Keep asking until we get a valid name."""
while True:
name = input("What's your name? ").strip().title()
if not is_string(name):
print("❌ Invalid name provided. Please enter text.")
continue
if is_valid_number(name):
print("❌ Name cannot be a number. Try again.")
continue
return name
def say_hello(name: str = "Manuel Morales") -> None:
parts = name.split()
first_name = parts[0]
last_name = parts[1] if len(parts) > 1 else ""
print(f"Hello, {first_name} {last_name}")
def main():
name = ask_name()
say_hello(name)
say_hello() # default greeting
if __name__ == "__main__":
main()