Table of Contents
ToggleQuestion
The included code stub will read an integer, n, from STDIN.
Without using any string methods, try to print the following:
123…n
Note that “…” represents the consecutive values in between.
Example:
n=5 Print the string 12345.
Input Format:
The first line contains an integer n.
Constraints:
1<=n<=150
Output Format:
Print the list of integers from 1 through n as a string, without spaces.
Sample Input 0
3
Sample Output 0
123
Solution
n = int(input())
for i in range (1,n+1):
print(i,end="")
In this code, we take the integer n
as input. Using a for loop, we iterate from 1 to n (inclusive) and print each number without a newline character by using end=''
.
Note: The code assumes that the input value of n is within the given constraints (1 <= n <= 150).
If you find anything wrong in this Solution, feel free to reach us in the comment section.