Thursday, July 21, 2022

[FIXED] How can I fix TypeError: 'int' object is not iterable?

Issue

How can I fix TypeError: 'int' object is not iterable?

N = list(input("Enter long number: "))

Even = []
Odd = []

for i in list (N):
    if i % 2 == 0:
        Even.count (i)
    elif i % 2 == 1:
        Odd.count (i)

print (f"Even: {Even}")
print (f"Odd: {Odd}")

Solution

can you try this?

N = list(input("Enter long number: "))

Even = []
Odd = []

for i in N:
    i = int(i)
    if i % 2 == 0:
        Even.append(i)
    elif i % 2 == 1:
        Odd.append(i)

print (f"Even: {Even}")
print (f"Odd: {Odd}")


Answered By - Gürkan KARADAĞ
Answer Checked By - Robin (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.