Range Printing

Write a Python program that prints all the numbers from 0 to n, inclusive, where n is a single integer input from the user.

Example 1:

Input: 5
Output: 0 1 2 3 4 5

Example 2:

Input: 2
Output: 0 1 2

You can use a for loop in combination with the range() function.

n = int(input())
for i in range(n+1):
    print(i, end=' ')

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!