Hello, I recently started my crash course programming in python.
I’m working on chapter six, dictionaries and lists.
If you look at my code, how can I formulate my if- statement so that when a list only contains one value, the string will be printed in the singular form (?
Now, I have specified the names if friend == ‘jim’ or ‘tim’ print in the singular form.
print(“\n” + friend.title() + “'s favorite number is:”)
However, I want to know if there’s a more general statement so it’s not name depended, but value depended, or if it is possible at all.
Thanks in advance.
> # Dictionary of my friends and their favorite numbers
>
> favorite_numbers = {'kim': [13, 48],
> 'jim': [4],
> 'wim': [55, 98, 3],
> 'tim': [9],
> }
> for friend, numbers in favorite_numbers.items():
> if friend == 'jim' or 'tim':
> print("\n" + friend.title() + "'s favorite number is:")
> else:
> print("\n" + friend.title() + "'s favorite numbers are:")
> for number in numbers:
> print(number)