Print Function - Hacker Rank Solution
Read an integer .
Without using any string methods, try to print the following:
Input Format
The first line contains an integer .
The first line contains an integer .
Output Format
Output the answer as explained in the task.
Output the answer as explained in the task.
Sample Input
3
Sample Output
123
Tip
You can use the print function inside a
You can use the print function inside a
map()
. Can you write a line code to solve the problem above?Print Function - Hacker Rank Solution
Problem Setter's code :
Python 2
from __future__ import print_function
print(*range(1, input() + 1), sep="")
Python 3
print(*range(1, int(input()) + 1), sep="")
Tested by DOSHI
Problem Tester's code :
Python 2
from __future__ import print_function
map(lambda x: print(x,end=''), range(1,input()+1))
Python 3
map(lambda x: print(x,end=''), range(1,input()+1))
print ''.join(map(str,range(1,int(raw_input()+1))))
ReplyDeleten = int(input())
Deletefor i in range(1,n+1):
print(i,end="")
not working showing compilation error
Deleteif __name__ == '__main__':
Deleten = int(input())
for i in range(1,n+1):
print(i, end = "")
Anyone looking for solution with explanation on print function?
Deletehere you go Hackerrank - Print Function Solution
a=input()
ReplyDeletex=""
for i in range(a,0,-1):
x=str(i)+x
print(x)
why this in range between (a,0,-10
Deleteit works
Deleteusing string not permitted
Deletefor i in range(n+1):
ReplyDeleteif i==0:
continue
print(i,end="")
would also work successfully
can you tell me, how does your range and print works in this..!!
Deletehttps://www.blogger.com/profile/02831904704265034785
Deletecan you tell me what is the use of end??
n = int(input())
Deletes=0
for i in range(n):
s=s+1
print(s,end="")
simple af:x
No it is not run properly
DeleteBy default there is a newline character appended to the item being printed (end='\n'), and end='' is used to make it printed on the same line.
Deleteif __name__ == '__main__':
ReplyDeleten = int(input())
for i in range(n+1):
if(i!=0):
print(i,end="")
correct answer
tell how n+1 is range im fully confused and where i comes from and print line how😥😥😥
Deletehere in print line end means
DeleteBy default there is a newline character appended to the item being printed (end='\n'), and end='' is used to make it printed on the same line.
Deletefrom __future__ import print_function
ReplyDeleten=int(raw_input())
for i in range(1,n+1):
print(i,end="")
It works...
Deleteimport numpy as np
ReplyDelete#enter number you want on below line prompt
n = int(raw_input())
arr = []
for i in range(1, n+1):
arr.append(i)
c = pow(10, (len(arr)-1))
arr2 = []
while(c >= 1):
arr2.append(c)
c = c/10
a = np.array(arr)
b = np.array(arr2)
c = a*b
print sum(c)
Can anyone tell me why this doesn't work ?
ReplyDelete```
n = int(input())
i=1
a=1
while(i<n):
a=a*10
i=i+1
a=a+i
print(a)
```
Because you take two variables one variable value enter from user and one you already declared and also initialised so that is why your program not run
Deleten = int(input())
ReplyDeletefor i in range(1,n+1):
print(i,end="")
not working
DeleteHi, I put:
ReplyDeletedef nums(N):
for i in range(1, N+1):
print(i, end="")
nums(3)
and the program returns me:
2/3 test cases failed :(
What do I do wrong?
change your for loop as
Deletefor i in range(N+1):
if i==0:
continue;
print(i,end="");
for i in range(n):
ReplyDeletei+1
print("{0}{1}{2}".format(i-1,i,i+1));
this is for pyton-3
#simplicity is the smart policy#
ReplyDeletetry it...
n = int(input())
for i in range(n):
print(i+1,end="")
n=int(input())
ReplyDeletefor i in range(1, n+1)
print(i, end="")
This worked for me
if __name__ == '__main__':
ReplyDeleten = int(input())
for i in range (1,n+1) :
print (i,end="")
n = int(input())
ReplyDeletefor i in range(1,n+1):
print(i,end="")
n=int(input())
ReplyDeletefor num in range(1,n+1):
print(f"{num}",end="")
# it will show red highlighted code but when you will run it, it will definitely work
Read an integer .
ReplyDeleteWithout using any string methods, try to print the following:
Note that "" represents the values in between.
Input Format
The first line contains an integer .
Output Format
Output the answer as explained in the task.
Sample Input 0
3
Sample Output 0
123
if __name__ == '__main__':
ReplyDeleten = int(input())
for i in range(1, n+1):
print(i, end = "")
if __name__ == '__main__':
ReplyDeleten = int(input())
z =41*n
print(str(z))
i=int(input())
ReplyDeleten=i
for i in range(1,n+1):
print(i,end="")
print(''.join((map(str, ((range(1, int(input())+1)))))))
ReplyDelete# Python 3 code - much efficient
n = int(input())
ReplyDeletex = 1
y = 0
while x <= n:
y = y*10 + x
x=x+1
print (y)
if __name__ == '__main__':
ReplyDeleten = int(input())
lst = []
for i in range(1,n+1):
lst.append(i)
print("".join(map(str,lst)))
from __future__ import print_function
ReplyDeleteif __name__ == '__main__':
n = int(raw_input())
for i in range(1,n+1):
print (i, end="")
def is_leap(year):
ReplyDeleteleap = False
# Write your logic here
if (year%4)==0:
if(year%100)==0:
if(year%400)==0:
leap=True
else :
leap= False
else :
leap = True
else:
leap= False
return leap
year = int(input())
print(is_leap(year))
if __name__ == '__main__':
ReplyDeleten = int(input())
s=""
for i in range(0,n):
i=i+1
s=s+str(i)
print(s)
n = int(input())
ReplyDeletex=""
for i in range (1,n+1):
x=x+str(i)
print(x)