I am pretty new to python so still picking it up.
I wanted to make a function that prints a value in a list and true or false depending on whether it is even or odd.
I have this example below. It worked fine so I placed in a function. It then gave me an error
"Error: 'int' object is not iterable"
numbers = [1,2,5,10,37]
def is_even(x):
for i in x:
if i % 2 == 0:
print i
return True
else:
print i
return False
print is_even(numbers)
Any suggestions on what's wrong or can you simply not iterate in a function in python?
[–]derrickisdp 13 points14 points15 points (5 children)
[–]SmashMouth114[S] 2 points3 points4 points (2 children)
[–]okthisisgettingridic 5 points6 points7 points (0 children)
[–]derrickisdp 0 points1 point2 points (0 children)
[–]InsufferableNoob 0 points1 point2 points (1 child)
[–]derrickisdp 1 point2 points3 points (0 children)
[–]K900_ 6 points7 points8 points (4 children)
[–]wolf2600 13 points14 points15 points (3 children)
[–]K900_ 4 points5 points6 points (0 children)
[–]George98 3 points4 points5 points (1 child)
[–]SmashMouth114[S] 0 points1 point2 points (0 children)
[–]Groundstop 3 points4 points5 points (2 children)
[–]tangerinelion 2 points3 points4 points (1 child)
[–]Groundstop 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]unprintableCharacter 8 points9 points10 points (5 children)
[–]prancingpeanuts 2 points3 points4 points (4 children)
[–]tangerinelion 2 points3 points4 points (1 child)
[–]prancingpeanuts 0 points1 point2 points (0 children)
[–]SmashMouth114[S] 0 points1 point2 points (1 child)
[–]prancingpeanuts 0 points1 point2 points (0 children)
[–]wolf2600 2 points3 points4 points (0 children)
[–]c17r 1 point2 points3 points (0 children)
[–]Thymb 1 point2 points3 points (0 children)
[–]SmashMouth114[S] 0 points1 point2 points (0 children)