# -*- coding: utf-8 -*-
"""
A program for playing around with dictionaries from Chapter 6 of Python Crash 
Course 3rd Ed. by Eric Matthes

Created on Wed Aug 7, 2024 13:40

@author: Volta
"""

print("How many people do you want to store info about")

#Promts user input, checks if user input is a positive integer, makes user
# correct input
passes_int = False
passes_pos = False
while passes_int != True or passes_pos != True:
    try:
        num_people = int(input())
    except:
        print("Number not an integer, try again")
        passes_int = False
        continue
    else:
        passes_int = True

    if num_people < 1:
        print("Number not positive, try again")
        passes_pos = False
    elif num_people == 0:
        print("Number must be a non-zero")
        passes_pos = False
    else:
        passes_pos = True

#Defining function to make ordinals
def ordinal(n: int):
    if 11 <= (n % 100) <= 13:
        suffix = 'th'
    else:
        suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]
    return str(n) + suffix

hometowns = {}
fav_colors = {}
names = []

for x in range(0,num_people):
    print(f"what is the {ordinal(x+1)} person's name?")
    name = input().lower()
    names.append(name)
    proper_name = name.title()
    if "s" in proper_name[-1]:
        possesive = f"{name.title()}'"
    else:
        possesive = f"{name.title()}'s"

    print(f"What is {possesive} home town?")
    hometown = input().lower()
    hometowns[name] = hometown

    print(f"What is {possesive} favorite color?")
    fav_color = input().lower()
    fav_colors[name] = fav_color

#print(hometowns)
#print(fav_colors)

#iterates through the dictionary and says what everyone's hometown and favorite
#color are

for name in names:
    hometown = hometowns[name]
    fav_color = fav_colors[name]

    if "s" in name[-1]:
        possesive = f"{name.title()}'"
    else:
        possesive = f"{name.title()}'s"
    
    print(f"{possesive} home town is {hometown.title()}")
    print(f"{possesive} favorite color is {fav_color}")

#This program could probably be enhanced by using nesting dictionaries
#however, I think that that is beyond the scope of this simple program