'what wrong? for and if code plz help me (python)

problem: Enter 10 integers and create a program that outputs the number of multiples of 3 and the number of multiples of 5 respectively.

ex)input: 10 15 36 99 100 19 46 88 87 13

ex)print: Multiples of 3 : 4 Multiples of 5 : 3

my code:

t=0
f=0
a=list(input().split())
for i in range(11):
    if int(a[i])%3==0: #index
        t+=1
    else:
        int(a[i]) % 5==0
        f += 1
    print('Multiples of 3 :',t)
    print('Multiples of 5 :',f)

error: if int(a[i])%3==0: IndexError: list index out of range enter code here

what's wrong? I don't know plz help me I an so angry



Solution 1:[1]

Try this python code snippet

t=0
f=0
n = int(input("Enter number of elements : "))
for i in range(0, n):
ele = int(input())
if (ele % 3) == 0:
  t = t + 1
elif (ele % 5) == 0:
  f = f + 1  
else: 
 print("element not counted")
print('Multiples of 3 :',t)
print('Multiples of 5 :',f)

I tried this code for list of 3 values of 3, 5 and 10 respectively

Running code snippet

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1