Z
Z
zhabaa2021-11-23 19:25:00
Python
zhabaa, 2021-11-23 19:25:00

Why doesn't if condition work in python?

When I run the code, for any value of a[i], count increases, tell me what is the problem?

a = input().split()
count = 0
for i in range(len(a)):
    if a[i] == 'a' or 'an' or 'the':
        count += 1

print(count)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-11-23
@zhabaa

if a[i] == 'a' or 'an' or 'the':

And how did you put two or three into one letter?
Better check with contains or in .

D
Denis Melnikov, 2021-11-23
@Mi11er

Because the comparison is only at the beginning a[i] == 'a'
The rest is like this
Write if a[i] in ['a','an','the']:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question