This issue relates to the number problem "1070", whose title is "Six Odd Numbers" made available by "Uri Online Judge" (Online Programming Marathon).
See here the entirety of the statement.
In this matter the usuário
enter a value inteiro X
. Then the program will calculate the NEXT 6
consecutive odd numbers, from the number typed X
.
In this matter we must OBSERVE the value of x. If the value of x
be odd, he too should be listed on exit. Otherwise should not be listed on exit.
Well, to solve this question we can use the loop of repetition while or for.
To resolve this issue using the while, we can use the following code:
x = int(input())
impar = 0
while impar < 12:
impar += 1
if x % 2 != 0:
print(x)
x += 1
And, to resolve this issue using the for, we can use the following code:
X = int(input())
for c in range(X, (X + 12)):
if c % 2 != 0:
print(c)
Note that in both codes we can notice the value 12 in evidence.
So why use the value 12 in the code?
The value 12 is equal to the product between amount values to be displayed and the footstep range. If the amount of values to be displayed is 6 and the pitch of the range is 2 - because the occurrence of each odd number in the set of integers is 2 in 2 - then, 6 x 2 = 12.
When we execute any of the codes, we receive a screen black with the mouse cursor blinking in the upper left corner of the screen. At this time we must enter an entire number and press enter
. From then on, the loop of repetition will perform the possible interactions and, with the help of the block if
, will be checked if each temporary value of the loop is odd. If positive, the function print()
will display its value.
These codes have already been testados
, submetidos
and properly aprovados
on the website Uri
, under programming language Python 3.