python - word fragments checker with a list and for loop analyzer -


i'm trying make semi-word analyzer, here code:

score = 0 letter_combos = ["hel","goo","the"] sentence = input("please enter sentence anaysing!") length = len(sentence) letter_combos in range (0, length):     score += 1             print(score) 

the idea is, if entered "hello there i'm today" should display score 3 printing length of sentence. on i've done wrong , need fix?

the pythonic way of solving problem use list comprehension:

letter_combos = ["hel", "goo", "the"] sentence = input("please enter sentence analyzing: ") score = sum(sentence.count(fragment) fragment in letter_combos) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -