Advertisement
Lyuben_Andreev

HobbyTuples

Jun 21st, 2024
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. def askPersonalInfo():
  2.     while True:
  3.         firstName = input("Input your first name: \t")
  4.         lastName = input("Input your last name: \t")
  5.         yearsBirth = input("Input your year of birth: \t")
  6.         gender = input("Input your gender (M, F): \t")
  7.  
  8.         if firstName == "" or lastName == "" or not yearsBirth.isdigit() or gender not in ("F", "M"):
  9.             print("Wrong data! Please enter valid information.")
  10.         else:
  11.             return firstName, lastName, yearsBirth, gender
  12.  
  13.  
  14. def askHobbies():
  15.     hobbyList = []
  16.     hobbyInd = 1
  17.  
  18.     while True:
  19.         hobbyName = input(f"Name of hobby {hobbyInd} (or type 'end' to finish): ")
  20.         if hobbyName.lower() == 'end':
  21.             break
  22.         elif hobbyName == "":
  23.             print("Hobby name cannot be empty.")
  24.         else:
  25.             hobbyList.append(hobbyName)
  26.             hobbyInd += 1
  27.  
  28.     return hobbyList
  29.  
  30.  
  31. # Main program flow
  32. personal_info = askPersonalInfo()
  33. hobbies = askHobbies()
  34.  
  35. print("\nPersonal Information:")
  36. print("First Name:", personal_info[0])
  37. print("Last Name:", personal_info[1])
  38. print("Year of Birth:", personal_info[2])
  39. print("Gender:", personal_info[3])
  40.  
  41. print("\nHobbies:")
  42. for i, hobby in enumerate(hobbies, start=1):
  43.     print(f"{i}. {hobby}")
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement