We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Introduction
- Print Function
- Discussions
Print Function
Print Function
+ 0 comments import math if name == 'main': n = int(input()) a = 0 m = 10**n for i in range(1, n+1): m = math.floor(math.log10(i))+1 m = 10**m a = a*m + i print(a)
+ 0 comments thats how it is done without print trick
import math if __name__ == '__main__': n = int(input()) a = 0 m = 10**n for i in range(1, n+1): m = math.floor(math.log10(i))+1 m = 10**m a = a*m + i print(a)
+ 0 comments for i in range(n): print(i + 1, end='')
+ 0 comments for i in range(1, n+1): print(i, end='')
+ 0 comments Since this is looking for a solution without using any strings, I think even list concatenation doesn't count as a valid one. I think they are expecting more or less something along the lines of:
if __name__ == '__main__': n = int(input()) a = 0; for i in range(1, n+1): if (i > 99): a = a*1000 + i elif (i > 9): a = a*100 + i else: a = a*10 + i print(a)
Load more conversations
Sort 2952 Discussions, By:
Please Login in order to post a comment