jeudi 15 octobre 2020

Printing singular/plural depending on dictionary value

favorite_languages = {'jen': ['python', 'ruby'], 'sarah': ['c'], 'edward': ['ruby', 'go'],
                  'phil': ['python', 'haskell'],}


for name, languages in favorite_languages.items():

   print("\n" + name.title() + "'s favorite languages are:")
   for language in languages:print("\t" + language.title())

output:Jen's favorite languages are:
Python
Ruby

Sarah's favorite languages are:
C
enter code here

Edward's favorite languages are:
Ruby
Go

Phil's favorite languages are:
Python
Haskell

i want to display "Sarah's favorite language is" instead of are. can not figure it out how to write the if statement to do this.

Aucun commentaire:

Enregistrer un commentaire