Python Print Function | HackerRank Solution

Hello coders, today we will be solving Python Print Function Hacker Rank Solution.

The included code stub will read an integer, n, from STDIN.

Without using any strings 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.

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 – Python Print Function – Hacker Rank Solution

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

Disclaimer: The above Problem (Print Function) is generated by Hacker Rank but the Solution is provided by CodingBroz. This tutorial is only for Educational and Learning purposes.

8 thoughts on “Python Print Function | HackerRank Solution”

1. What is wrong in this code?
n=int(input())
for i in range(0,n):
i=i+1
print(i, end=” “)

1. Ömer Faruk Dilbaz

Because numbers don’t start from 0. You have to change the interval scale. The last number is not 0 and the for loop is automatic plus one, if you add 1 again you add two to i. I suggest you look at the for loop again

2. if __name__ == ‘__main__’:
n = int(input())
if 1<=n<=150:
for i in range(1,n+1):
print(i)

3. The provided code stub reads two integers from STDIN, and . Add code to print three lines where:

The first line contains the sum of the two numbers.
The second line contains the difference of the two numbers (first – second).
The third line contains the product of the two numbers.
Example

Print the following:

8
-2
15
Input Format

The first line contains the first integer, .
The second line contains the second integer, .

Constraints

Output Format

Print the three lines as explained above.

Sample Input 0

3
2
Sample Output 0

5
1
6