4
My code needs show an int number greater than 2 and need to print the sequence of even numbers smaller than itself and need to start from scratch.
If you are less than 2 have to print Invalid number
Example:
Entrada = [20]
Saída = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
My code (not running):
seqpair = input("Type a number pair: ")
seqpair = list(map(int, seqpair.split()))
if seqpair > 2:
print (seqpair)
else:
print ('Invalid number')
list = list(range(0, number + 1, 2)) explain this part of the code?
– user141036
@Alexfeliciano The range(0, number + 1, 2) means that it will create a range object starting from 0 until number + 1 jumps from 2 to 2, then the range is converted into a list and assigned to its list variable
– Vinicius Fernandes
Good solution, but ai tb has an iteration of type list comprehension, with the additional cost of the
if
– Sidon
@Alexfeliciano commented the code to facilitate the explanation
– Vinicius Fernandes
@Sidon how so if? additional cost if I have not used any if
– Vinicius Fernandes
if number>2
additional line I meant. Actually an additional block– Sidon
@Sidon thus, ta specified in Alex’s question that if the number is less than 2 should print Invalid number
– Vinicius Fernandes
It’s true @Viniciusfernandes I ate ball, Sorry! :-)
– Sidon