-3

I want to make a grammar checker with Python. But this is not going to be a standard grammar checker. This is intended for learners of the English language who are at the beginner level. I wrote the following code to check if the user uses the correct form of the verb:

preList = ['came', 'waited', 'sat', 'stood', 'went', 'left']
sentence = input("Type a sentence using the past simple tense: ")
sentence = sentence.split()
if sentence[1] or sentence[2] or sentence[3] in preList:
print("Looks good!")
else:
print("Maybe you're missing something!") 

The problem I have is that even if the user input does not contain any of the words in preList, it prints "Looks good". What is the problem with my code?

Kaptan Singh
  • 221
  • 1
  • 3
  • 11

1 Answers1

0

Correct the if-clause to

if sentence[1] in preList or sentence[2] in preList or sentence[3] in preList:
elzell
  • 2,228
  • 1
  • 16
  • 26
  • 1
    it's clearly not the best solution: 1) what if there are less than 4 words? 2) indexes start at 0 in python 3) using `any` on the list is probably more pythonic. When answering such bad questions, at least make the effort of improving the code, not just point out blatant mistakes. – Jean-François Fabre Mar 01 '17 at 16:34
  • @Jean-FrançoisFabre What miserable lives we would have if there were no Stack Exchange! – Kaptan Singh Mar 01 '17 at 16:50
  • @KaptanSingh I recommend that you read the answers in the duplicate link. Very instructive to really learn the pythonic ways and the explanation of your common mistake. – Jean-François Fabre Mar 01 '17 at 16:54
  • @Jean-FrançoisFabre I appreciate your efforts. I am sure going to improve over time. You know, I've just begun learning Python. I will read what you've suggested and a lot more. A small success in the beginning is not really small. – Kaptan Singh Mar 01 '17 at 17:01