Hello, I’m doing the CODE CHALLENGE: STRING METHODS and I got a question on the task X length.
Sorry for might be a stupid question and I tried to search online and here in the forum before I posted. Hopefully someone can help me!
- Create a function called
x_length_wordsthat takes a string named
sentenceand an integer named
xas parameters. This function should return
Trueif every word in
sentencehas a length greater than or equal to
This is my code:
def x_length_words(sentence,x): sentence_list = sentence.split() for word in sentence_list: if len(word) <= x: re = False else: re = True return re
This is the answer you get if you ask for the solution:
def x_length_words(sentence,x): sentence_list = sentence.split(" ") for word in sentence_list: if len(word) < x: return False return True
I am wondering why my code doesn’t work? Am I using
Thank you in advance!