Instagram
youtube
Facebook
Twitter

Python Print Function HackerRank Solution


In this article, we will solve the HackerRank Print Function problem in Python.

Task

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

1 2 3

 

Solution:

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

Steps Used in solving the problem -

Step 1: first n will take int type input.

Step 2: then we used a for loop in the range between 1 to n+1. I have given a range from 1 to n+1 so, the compiler should take n.

Step 3: After this the print function will print the values in the range (1, n+1). Here, end=’ ’ will print the numbers in a single line.