3 consecutive words | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

3 consecutive words

Can someone help me solve this please ? I have to write the code so it check if a string have 3 consecutive words def checkio(text: str): ... Exemple assert checkio("Hello World hello") == True assert checkio("He is 123 man") == False assert checkio("1 2 3 4") == False assert checkio("bla bla bla") == True

19th May 2024, 9:46 PM
Hood♠️👨🏿‍💻
Hood♠️👨🏿‍💻 - avatar
6 Antworten
+ 8
Toni Isotalo , it is not seen as very helpful when we are going to post a ready-made code, as long as the op has not shown his attempt here. it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself.
20th May 2024, 5:41 AM
Lothar
Lothar - avatar
+ 7
Hood♠️👨🏿‍💻 here is maybe a close example of what you may be looking for https://sololearn.com/compiler-playground/cXtrtvDj3WWh/?ref=app
19th May 2024, 10:35 PM
BroFar
BroFar - avatar
+ 7
Hood♠️👨🏿‍💻 , i have some doubts about your last sample in the code: checkio("bla bla bla bla") == True if we are looking for *3 consecutive words* the result should be *False* since there are 4 words in the string.
20th May 2024, 5:43 AM
Lothar
Lothar - avatar
+ 4
words = text.split(" ") w = None num = 1 for a in words: if(a == w): num = num + 1 else: num = 1 w = a if(num == 3): return True return False Untested and written while on bed on my phone. But I hope you get the idea
19th May 2024, 10:24 PM
Toni Isotalo
Toni Isotalo - avatar
0
Guys Please sand me any simple cod
21st May 2024, 6:43 PM
Amanuel Worku
Amanuel Worku - avatar