w3resource

Python: Generate and prints a list of numbers from 1 to 10

Python Basic - 1: Exercise-115 with Solution

Write a Python program to generate and print a list of numbers from 1 to 10.

Expected output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
['1', '2', '3', '4', '5', '6', '7', '8', '9']

Sample Solution:

Python Code:

nums = range(1,10)
print(list(nums))
print(list(map(str, nums)))

Sample Output:

[1, 2, 3, 4, 5, 6, 7, 8, 9]
['1', '2', '3', '4', '5', '6', '7', '8', '9']

Flowchart:

Flowchart: Python - Generate and prints a list of numbers from 1 to 10.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to print letters from the English alphabet from a-z and A-Z.
Next: Write a Python program to identify nonprime numbers between 1 to 100 (integers). Print the nonprime numbers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.