0
Name buddies Test #5 fail?
This is my code for class buddies: classm = input() yname = input() classm = list(classm) for name in classm: if name[0] == yname[0]: print("Compare notes") break else: print("No such luck") break Everything passed except test #5. What am I doing wrong?
4 Respostas
+ 4
I do not remember the task but you want to check for all items with
for name in classm:
and you code name[0] == … ?
+ 3
Talkiestcobra6 ,
> the *if* part of your conditional statement is correct.
> the *else* part however has an issue. it will break with the first name that *not matches*, but should continue with checking the names.
> make *else* as a part of the for loop...
+ 1
Hey there!
The list function will get every elements from an "object", such as Dictionaries, Tuples, Set, etc.. But if you use the list function to get every elements from a string, it will get every character inside it, instead of getting every words. For example, "Hello world" would return ["H","e","l",...,"d"] within list function.
I think it is better to use the split() function for the list of names, and a for loop to access every elements in the list created using the split() function.
split() syntax: [STRING].split("[CHARACTER TO SEPARATE, CAN BE EMPTY FOR SEPARATING BY SPACE]")
Now, you will have to loop through the elements of the given list. Use indexing to get the specific character of every word in a list.
(Split function is very useful when you want to make a string into a list containing words, and separated by a specific character given in the string.)
+ 1
Oh yeah..
If you don't want to use the split() function and prefer complete the challenge with your code, then you can use boolean values. For default value, you'd like to set your default boolean value to False in case we don't find any names in the list that has the first letter the same as the name user input. In this case, the else statement in the for loop is not needed.