Python: Find a string consisting of the non-negative integers up to n inclusive
Create String of Non-Negatives to n
Write a Python program to create a string consisting of non-negative integers up to n inclusive.
Input: 4 Output: 0 1 2 3 4 Input: 15 Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Visual Presentation:

Sample Solution-1:
Python Code:
Sample Output:
Non-negative integer: 4 Non-negative integers up to n inclusive: 0 1 2 3 4 Non-negative integer: 15 Non-negative integers up to n inclusive: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Flowchart:

Sample Solution-2:
Python Code:
Sample Output:
Non-negative integer: 4 Non-negative integers up to n inclusive: 0 1 2 3 4 Non-negative integer: 15 Non-negative integers up to n inclusive: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to generate a string that contains non-negative integers from 0 to n separated by spaces.
- Write a Python program to convert the sequence of numbers from 0 to n into a single space-separated string.
- Write a Python program using join() to create a string of numbers from 0 to n in order.
- Write a Python program to build a string from a range of integers (0 to n) using list comprehension and string concatenation.
Go to:
Previous: Find the strings in a list containing a given substring.
Next: Find the indices of all occurrences of target in the uneven matrix.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.