Home > other >  Small white inquired, in front of the traverse if statements, there are different types of len deter
Small white inquired, in front of the traverse if statements, there are different types of len deter

Time:10-08

6.4.2 python from entry to practice the sixth chapter, there is a development, I really don't understand here!

# multiple keys stored list values,
Favorite_languages={
'jen: [' python', 'ruby'],
'Sarah: [' c'],
'Edward: [' ruby,' go '],
'phil: [' python', 'haskell'],
}
For the name, the languages in favorite_languages. The items () :
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
For language in languages:
Print (" \ t "+ language. The title ())

Development: in order to further improve the program, but for loop of the traverse the dictionary first add an if statement, by looking at the len (languages) value to determine the current respondents like whether there is a variety of language, if he likes to many languages, like previous display output; If there is only one, the wording of the corresponding modified output, such as display Sarah 's favorite language is C,

Here the expansion of what to do?

Happy New Year!!!!!

CodePudding user response:

 
For the name, the languages in favorite_languages. The items () :
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
If len (languages)!=1:
For language in languages:
Print (" \ t "+ language. The title ())
The else:
Print (I don't know how to write)

CodePudding user response:

For the name, the languages in favorite_languages. The items () :
If len (languages)==1:
Print (name. Title () + "' s favorite laguages is:")
The else:
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
For language in languages:
Print (" \ t "+ language. The title ())
Reference code out of the 1/f, as a result, I wrote before is STR (len

CodePudding user response:

The
reference 2 floor & lt; Span style="color: # 4788 c7" & gt; M0_46288466 & lt;/span> Response:
for name, languages in favorite_languages. The items () :
If len (languages)==1:
Print (name. Title () + "' s favorite laguages is:")
The else:
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
For language in languages:
Print (" \ t "+ language. The title ())
Reference code out of the 1/f, as a result, I wrote before is STR (len
& lt; br/> The results, but with the STR or is full, without the STR's right, this is a bit don't understand.

CodePudding user response:

Favorite_languages={
'jan: [' python', 'ruby'],
'tia: [' sas'],
'qqa: [' Java', 'python],
}
For the name, the languages in favorite_languages. The items () :
If len (languages)!=1:
Print (' \ n '+ name. Title () +' \ 's favorite languages are:')
The else:
Print (' \ n '+ name. Title () +' \ 's favorite language is:')
For language in languages:
Print (' \ t '+ language)

CodePudding user response:

The
reference 3 floor m0_46288466 response:
Quote: reference 2 floor & lt; Span style="color: # 4788 c7" & gt; M0_46288466 & lt;/span> Response:
for name, languages in favorite_languages. The items () :
If len (languages)==1:
Print (name. Title () + "' s favorite laguages is:")
The else:
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
For language in languages:
Print (" \ t "+ language. The title ())
Reference code out of the 1/f, as a result, I wrote before is STR (len
& lt; br/> The results, but with the STR or is full, without the STR's right, a little don't understand this,

Added STR output is the result of the '1', is still!=1, so you may as well,

CodePudding user response:

Favorite_languages={
'jen: [' python', 'ruby'],
'Sarah: [' c'],
'Edward: [' ruby,' go '],
'phil: [' python', 'haskell'],
}
# if len (languages)==1:
# print (name. Title () + "' s favoite langiges are" + language)
For the name, the languages in favorite_languages. The items () :
If len (languages)==1:
# print (name. Title () + "' s favoite langiges are" + STR (join (favorite_languages [name])))
Print (name. Title () + "' s favoite langiges are" + languages [0])

The else:
Print (" \ n "+ name. Title () +" 's favoite langiges are: ")
For language in languages:
If len (languages)==1:
Print (')
The else:
Print (" \ t "+ language. The title ())

CodePudding user response:

refer to 6th floor feeling in the test response:
favorite_languages={
'jen: [' python', 'ruby'],
'Sarah: [' c'],
'Edward: [' ruby,' go '],
'phil: [' python', 'haskell'],
}
# if len (languages)==1:
# print (name. Title () + "' s favoite langiges are" + language)
For the name, the languages in favorite_languages. The items () :
If len (languages)==1:
# print (name. Title () + "' s favoite langiges are" + STR (join (favorite_languages [name])))
Print (name. Title () + "' s favoite langiges are" + languages [0])

The else:
Print (" \ n "+ name. Title () +" 's favoite langiges are: ")
For language in languages:
If len (languages)==1:
print (') changed to: pass
The else:
Print (" \ t "+ language. The title ())

CodePudding user response:

If certain languages is only one element, then direct it to a string can be: languages [0]
For the name, the languages in favorite_languages. The items () :
If len (languages)==1:
Print (name. Title () + f "' s favorite laguages is: {languages [0]}
")The else:
Print (" \ n "+ name. Title () +" 's favorite languages are: ")
nullnull
  • Related