Rishav Mitra
Rishav Mitra

Reputation: 21

Zero in-front of a number getting deleted

The below program snippet is running fine with any inputs except those starting with 0

NK = list(map(int,input().split()))
string = input()
print(string)
n = int(string)
A = [int(x) for x in str(n)]
print(A)

N = NK[0]
K = NK[1]

for i in range(K):
    temp = A[0]
    for j in range(0,len(A)-1):
        A[j] = A[j+1]
    A[N-1] = temp
print(A)

For input

5 3
01111

Im getting error since while converting the string to int the leading 0 is getting deleted. Is there any way to stop that from happening?

Upvotes: 0

Views: 47

Answers (1)

Hamed Ghennat
Hamed Ghennat

Reputation: 106

remove below line:

n = int(string)

and change this line :

A = [int(x) for x in str(n)]

to this :

A = [int(x) for x in string]

Upvotes: 1

Related Questions