I am new to coding and I'm doing an assignment for school where we have to write a program that asks how many people in your family you are shopping for during the holidays and how much you are going to spend on each one. We are also defining a favorite, so the person you are spending the most on is the favorite.
So far I've written the code so that it asks for the number of people you are shopping for, the amount you are spending on each, and then it defines a favorite. The part that I'm stuck with is if there is no maximum amount; for example, if you are spending $100 on more than one person, or you are spending the same amount for everyone.
This is what I have so far
def family_names():
print("It's holiday season! \n")
names = []
n = int(input("How many family members are you shopping for this year? "))
print()
for i in range(n):
names.append(input("Enter your first family member's name: ").title())
return names
def spend(family):
print()
amount = []
for i in family:
print("How much will you spend on ", i, "? ", sep ="", end ="")
amount.append(int(input()))
return amount
def favorite(family, amount):
price = amount.index(max(amount))
fav = family[price]
print(fav, " is your favorite family member because you spent $", max(amount), " on them.", sep = "")
#-----main-----
people = family_names()
money = spend(people)
favorite(people,money)```