- 1
Hi, I wrote this code to solve a problem, can someone say me if there is a shorter or easier way to do it?
If a sentence flows, the first letter of each word will be the same to the last letter of the previous word. Task: 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. Casing does not matter. Input Format: A string containing a sentence of words. Output Format: A string: true or false. Sample Input: this string gets stuck Sample Output: true Here's the code https://code.sololearn.com/cLXbF8PftpOo/?ref=app
4 odpowiedzi
- 1
Please describe what the code is supposed to do and what input you expect.
- 1
Done
- 1
Where is this task from? 🤔
sentence = input().lower().split(" ")
i = len(sentence)-1
while i>0:
first_letter = sentence[i][0]
i-=1
final_letter = sentence[i][-1]
b = final_letter == first_letter
if not b: break;
print(b)
- 1
It was a code coach
it's named flowing words
Thank you so much!!!