Aug-08-2020, 05:56 PM
Hi,
This is not happening, hence the code does not work.
The following loop:
- the condition is not met since ,,this,, is 4 characters long.
Therefore the code moves on to:
Quote:first iteration passing over "this" produces a False and so the function should continue on to the second word in the list "is",
This is not happening, hence the code does not work.
The following loop:
for wd in xs: if len(wd) == 2: return wd return " "will not loop through the whole list simply because the code checks:
if len(wd) == 2:
- the condition is not met since ,,this,, is 4 characters long.
Therefore the code moves on to:
return " "- this simply exits the for loop returning empty string " " and the code then moves on to:
print("The first 2 letter word is ", find_first_2_letter_word(xs))You do not want to exit the loop after the first iteration :) Delete/comment out the line that makes the loop exit and the code should work.