I have to iterate through a list using a for loop. In the list, I have to see if the number is even, and if it is, I have to add one to it, and if it is odd, I also have to add one to it. Then i have to print it.
So, the list is [1,2,3,4,5,6,7,8,9,10] and the desired output would be [2,3,4,5,6,7,8,9,10,11].
samplenumber = [1,2,3,4,5,6,7,8,9,10]
for i in samplenumber:
if i%2 == 0:
print (samplenumber 1)
else:
print (samplenumber 1)
This is my code above^^
CodePudding user response:
Maybe you made a mistake but it seems like you're adding one to the number regardless of its even or odd property. I mean, so what is the point of knowing if the number is odd or even? Maybe a school technical excercise?
CodePudding user response:
According to your required Answers, the code will be like this:
samplenumber = [1,2,3,4,5,6,7,8,9,10]
for i in samplenumber:
j= 1
a=int(i) j
print (a, end=",")