+ 1

Flowing words

Can anyone help I solved it but the case number 3 still wrong why???

16th Sep 2024, 3:21 AM
Menna Elsayed
Menna Elsayed - avatar
6 ответов
+ 4
Menna Elsayed , this depends on the input data (strings) test cases provided from sololearn: > the first one has only 2 words and is meeting the requirements > the second one has more words, but all of them are meeting the requirements. > for all the other cases we can not see what input is used try to rework the code as described in my last post. i just saw that you have modified your code. now all word pairs are checked. but we have the issue, that `true` or `false` is printed repearedly after each check. it should be printed only once as the last step.
18th Sep 2024, 3:31 PM
Lothar
Lothar - avatar
16th Sep 2024, 6:56 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Menna Elsayed , do you try to solve the challange in the code coach? https://www.sololearn.com/coach/87?ref=app >> just a hint: > the current code checks if the *last char of the first word* is equal to the *first char of the second word*. > if this is true, `true` will be returned, but we do not check the following words. read the task description: Write a program that takes in a string that contains a sentence, checks if the first letter of **each** word is the same as the last letter of the previous word. If the condition is met, output true, if not, output false.
16th Sep 2024, 6:57 PM
Lothar
Lothar - avatar
+ 1
def flowing_words(sentence): sentence = sentence.split(' ') le= len(sentence) for i in range(len(sentence)-1) : if sentence[i][-1] == sentence[i+1][0]: return 'true' else: return 'false' print (flowing_words (input())) That's my code
16th Sep 2024, 8:19 AM
Menna Elsayed
Menna Elsayed - avatar
+ 1
I understand but why just the case number 3 still wrong?
18th Sep 2024, 1:07 PM
Menna Elsayed
Menna Elsayed - avatar
+ 1
Yeah that's right it's working now thank youuu
18th Sep 2024, 4:05 PM
Menna Elsayed
Menna Elsayed - avatar