The best thing for your problem is to use the function range(minValue, maxValue, step)
, because you can iterate perfectly as the description asks, and to check if a number is divisible by 7, just use the operator %
entire split rest, if the rest of the split is 0 add the value to the list, using the method append(value)
.
print('''Inicio do Programa''')
minValue = int (input('Digite um numero Minimo inteiro: '))
maxValue = int (input('Digite um numero Maximo inteiro: '))
L = []
for i in range(minValue, maxValue + 1, 1):
if (i % 7 == 0):
L.append(i)
print(L);
Another option would also be using multiple range:
minValue = int(input('Digite um numero Minimo inteiro: '))
maxValue = int(input('Digite um numero Maximo inteiro: '))
print(*range(minValue + (7 - minValue % 7), maxValue + 1, 7))
It’s more compact but less readable.
It works that way:
First multiple to minimum value partier = Min + (7 - Min % 7)
(7 - Min % 7)
is how much missing from the minimum to the next multiple.
The heel (step
) is equal to 7 why we have the guarantee that the first is a multiple.
maxValue + 1
because the function range
from 0 to maxValue - 1.
as well as multiples range?
– ronalds
@Ronalds, an Rage of multiples of 7 starting at a multiple of 7
– Augusto Vasques
got it thank you
– ronalds