Python Forum
'string index out of range' error when code replaces characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'string index out of range' error when code replaces characters
#2
Don't worry guys i found the problem
i need to change 'blanks = '-'*len(secretWord)' to blanks = ['-']*len(secretWord)
and then change 'blanks = secretWord[i] + blanks[:i] + blanks[i+1]' to blanks[i] = secretWord[i]
Reply


Messages In This Thread
RE: 'string index out of range' error when code replaces characters - by Ivan - Mar-04-2017, 05:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  doing string split with 2 or more split characters Skaperen 22 2,567 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,879 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  pyscript index error while calling input from html form pyscript_dude 2 999 May-21-2023, 08:17 AM
Last Post: snippsat
  Index error help MRsquared 1 778 May-15-2023, 03:28 PM
Last Post: buran
Thumbs Down I hate "List index out of range" Melen 20 3,358 May-14-2023, 06:43 AM
Last Post: deanhystad
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,559 Apr-12-2023, 10:39 AM
Last Post: jefsummers
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 6,419 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  IndexError: list index out of range dolac 4 1,929 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  I'm getting a String index out of range error debian77 7 2,363 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,450 May-03-2022, 01:39 PM
Last Post: Anldra12

Forum Jump:

User Panel Messages

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