Print Function - Hackerrank solution

 

Print Function


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.


Solution:

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

Note:

This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

 The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You. 


 

Print Function - Hackerrank solution Print Function - Hackerrank solution Reviewed by CodexRitik on March 15, 2020 Rating: 5

6 comments:

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

    This will also works

    ReplyDelete
  2. my code is not working at end it's showing undefined variable.

    ReplyDelete
  3. why have we used end here why not anything else ??

    ReplyDelete

Powered by Blogger.