The main problem with your code:
x=int(input())
impar=0
while(impar<6):
x=x+1
impar=+1
if(x%2 != 0):
print('%d' %x)
You've confused the operator to "add value to variable" - which would be +=
with =+
. Because Python ignores spaces between mathematical operators, the impar=+1
sequence simply means impar = +1
. That is, your variable that would be the counter is always worth "1", and therefore always less than 6 - and the condition of while
is always true.
In the upper line of these, you have put x = x + 1
in extension - that is, get the previous value of x, sum 1, and assign this new result to x
. The +=
operator used correctly does just that - then the two lines could be x += 1
and impar += 1
(or x = x + 1
and impar = impar + 1
)
This is not the only bug in this code - if you fix it, it is no longer infinite, and you may be able to sort out the rest by analyzing the new results. If you do not mind, I'll close the answer here, and leave some of the challenge back to you.
If you continue to need help, please indicate in the comments, please.