Python Forum

Full Version: User input - list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys, please, is there any way how to replace this bz user input? [10,20,10]
If I change the firts row to zakodovat2 = ['Insert list of numbers'] and write 10,20,10 manually then I always get an error... thanks for any advice!
zakodovat2 = [10,20,10]
    zakodovat2 = [10,20,10]
    delka = len(zakodovat2)
    kod = ''
    for i in range(0,delka):
        cislo = int(zakodovat2[i])
        pismeno = chr(cislo+96)
        kod = kod + pismeno
    print(kod)
Quote:If I change the firts row to zakodovat2 = ['Insert list of numbers'] and write 10,20,10 manually then I always get an error... thanks for any advice!
Not sure what you mean? Please show code example of this scenario.
First, change kod to a list and append as you only print the last loop through the for
##    kod = kod + pismeno
    kod.append(pismeno)
print(kod)
you can't append if a list doesn't already exist.
at beginning, add:
kod = []