This is not exactly homework. I am solving Python3 Practice problems in HackerRank to learn python coding. I am stuck on a mathematical logic part. In the program below, I describe the purpose of the program in the first comment block. In the second comment block, I explain the challenge I am encountering. I am not asking for a python code solution. I am asking for mathematical logic to overcome my problem.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Oct 12 00:05:37 2019 @author: deep """ ''' Read an integer N. Without using any string methods, try to prin the following: 123....N Example: N=3 output: 123 ''' ''' Not working for N > 9. So N=10 should give an output 12345678910 instead my program gives 123456790. I understand why this is happening as far as coding is concerned but I cannot figure out what mathematical logic I need to employ to tackle to address the additional digit once N changes by a factor of 10 ''' # Creating function to reverse a list def Reverse(lst) new_lst = lst[::-1] return new_lst # Enter number N= int(input('Enter a number: ')) Nabs= abs(N) x=[] # List of numbers starting from 0 to N-1 y=[] # Reverse of list x[] z=[] # List of numbers from 1 to N+1 # Populating list x by appendng with numbers from 0 to N-1. for i in range(Nabs): x.append(i) print(x) # Length of list lx=len(x) print('length: ', lx) # Creating reverse list by calling Reverse function for which function has been defined in the beginning of the program. This list will act as the place value calculator as a multiple of 10 y=Reverse(x) print(y) # Creating list raning from 1 to N+1 which will act as the list of coefficients that will be multiplied to the elements in the place value list for j in range(1, Nabs+1): z.append(j) print(z) # Defining parameters: a is used to calculate the product of the coefficients and the place value. b is used to calculate the sum a=0 b=0 for k in range(lx): a=z[k]*(10**y[k]) b=b+a # Negative sign check if N<0: b=-b print(b)