Q:

Generate a Python list of all the even numbers between 4 to 30

3

Generate a Python list of all the even numbers between 4 to 30

Expected Output:

[4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

  • Use the built-in function range() to generate the sequence of numbers between the given start number to the stop number with a step = 2 to get even numbers.
  • pass range() function to a list constructor to create a list

solution:

print(list(range(4, 30, 2)))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now