+ 2
Help with code
Hi, im trying to write program that do following: input(n) print 1234....n without using string methods i make this code but something doesnt go as planned and i dont know what it is. if __name__ == '__main__': n = int(input()) answer = 0 for i in range(n+1): x = i % 10 answer = answer * 10 answer =+ x i =+ 1 print(answer) as you can see i add the answer * 10 to "move the number to the left", but it looks like it does nothing
4 Answers
+ 5
You could do it like this
for i in range(1,int(input())+1):
print(i,end ="")
+ 3
# Use this instead
answer += x
i += 1
+ 2
OMG such a small mistake :D i hate my Dyslexia thx :D
the problem was i had =+ instead of +=
0
Also it work only till input = 9 :D so now the new task begin :D
Edit: This is how it works now for numbers smaller that 1000. I just need input in range(150). :)
if __name__ == '__main__':
n = int(input())
answer = 0
for i in range(n+1):
x = i % 10000
if i < 10:
answer = answer * 10
elif 10 <= i <100:
answer = answer * 100
else:
answer = answer * 1000
answer += x
i += 1
print(answer)