9
9
97802021-09-05 19:03:47
Python
9780, 2021-09-05 19:03:47

Error string index out of range?

a friend threw off a code that makes letters from numbers. Example 01=a 02=b. If I write 0201 then the program should display ab. It throws an error string index out of range. Who knows how to solve it please tell me.
a = input()
dict = { "01" : "a",
"02" : "b"
}
n = 0
m = 1
for i in range(0, len(a)-1):
k = a[n ]
f = a[m]
p = k + f
print(dict[p])
n = n + 2
m = m + 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ajderha, 2021-09-07
@9780

A step needs to be added. Trying to access a non-existent index
for i in range(0, len(a)-1, 2):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question