I am trying to condition this output so that each string is printed and formatted equally with the exception of "sarah". I've got this to work with the wording of her output being unique as she has only 1 "favourite language". However, now her language "C" is also in Jen's favourite language list when it shouldn't be. I tried using an elif/else
in place of the 2nd if
and got an invalid syntax error
. I don't know how this is happening, thanks.
favourite_languages = {
"jen": ["python", "ruby"],
"sarah": ["c"],
"edward": ["ruby", "go"],
"phil": ["python", "haskell"],
}
for name, languages in favourite_languages.items():
if len(languages) != 1:
print(f"
{name.title()}'s favourite languages are:")
for language in languages:
print(f"{language.title()}")
if len(languages) == 1:
print(f"
{name.title()}'s favourite language is:")
print(f"{language.title()}")
output:
Jen's favourite languages are:
Python
Ruby
C
Sarah's favourite language is:
C
Edward's favourite languages are:
Ruby
Go
Phil's favourite languages are:
Python
Haskell
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…