Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User input - list
#1
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)
Reply
#2
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.
Reply
#3
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)
Reply
#4
you can't append if a list doesn't already exist.
at beginning, add:
kod = []
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 136 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 351 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  How to time a user's input Tbot1000 2 278 Aug-31-2020, 09:39 PM
Last Post: Larz60+
  converting user input to float troubles RecklessTechGuy 3 396 Aug-17-2020, 12:41 PM
Last Post: deanhystad
  Validating user input WJSwan 2 358 Jul-06-2020, 07:21 AM
Last Post: menator01
  Hi, I need help with defining user's input and applying it to code. jlmorenoc 2 453 Jun-24-2020, 02:10 PM
Last Post: pyzyx3qwerty
  taking input doesnt print as list bntayfur 2 354 Jun-04-2020, 02:48 AM
Last Post: bntayfur
  if the input is not number, let user input again teatea 14 965 Jun-02-2020, 07:03 PM
Last Post: ibutun
  How to allow user input only if certain requirements are met vininhosts 3 457 May-28-2020, 06:15 PM
Last Post: micseydel
  Python - Most effective way to correct keyboard-user-input. ppel123 8 691 Apr-08-2020, 07:41 AM
Last Post: ppel123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020