Python uri online judge

0

Read an integer value X. Then display the 6 consecutive odd values from X, one value per line, even if X is the case.

Entry: the entry will be a positive integer value.

Output: The output will be a sequence of six odd numbers.

x=int(input())
impar=0
while(impar<6):
 x=x+1
 impar=+1
 if(x%2 != 0):
   print('%d' %x)

How do I get out of infinite printing and print only 6?

    
asked by anonymous 14.10.2018 / 15:53

2 answers

2

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.

    
15.10.2018 / 15:12
1

Your program is almost ready, just needing small adjustments that I think you should have done, but in any case "there it goes" (with the numbers I tested worked):

x = int(input())
impar = 0
while(impar<11):
 x = x + 1
 impar += 1
 if(x%2 != 0):
  print('%d' %x)
    
18.10.2018 / 22:21