Hello, I am on this exercise below:
Python Strings | Codecademy
finally decided to look at the solution and I have two questions referring to their solution.
First question: Why does the solution not use an else
statement for the return False
Second question: In my eyes, my solution should yield the same exact result as the solution but it doesnt! look at the code below to see the difference between my code and the solution. It is the same thing but just switched around
Codecademy Solution:
def x_length_words(sentence, x):
words = sentence.split(" ")
for word in words:
if len(word) < x:
return False
return True
MY Solution:
def x_length_words(sentence, x):
split_sen = sentence.split()
for words in split_sen:
if len(words) > x:
return True
else:
return False
As you can see, I have if len(words)> x return True
and they have if len(words) < x return false
Why is this not the same thing??