Python Forum
List index out of range error when attempting to make a basic shift code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List index out of range error when attempting to make a basic shift code
#3
Rather than keeping track with another number (so you have something to change in multiple places), you can use the mod operator and the actual array.

Instead of
            if new_position > 26:
                new_position = new_position - 27
Consider
            new_position %= len(alphabet)
Reply


Messages In This Thread
RE: List index out of range error when attempting to make a basic shift code - by bowlofred - Aug-16-2020, 06:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 111 3 hours ago
Last Post: CandleType1a
  hi need help to make this code work correctly atulkul1985 5 886 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 744 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Cleaning my code to make it more efficient BSDevo 13 1,535 Sep-27-2023, 10:39 PM
Last Post: BSDevo
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,442 May-22-2023, 10:39 PM
Last Post: ICanIBB
  pyscript index error while calling input from html form pyscript_dude 2 1,044 May-21-2023, 08:17 AM
Last Post: snippsat
  Index error help MRsquared 1 839 May-15-2023, 03:28 PM
Last Post: buran
Thumbs Down I hate "List index out of range" Melen 20 3,548 May-14-2023, 06:43 AM
Last Post: deanhystad
  how to make bot that sends instagram auto password reset code kraixx 2 1,469 Mar-04-2023, 09:59 PM
Last Post: jefsummers
  Find a shift between 2 pictures TazFleck 0 1,237 Jan-18-2023, 09:56 PM
Last Post: TazFleck

Forum Jump:

User Panel Messages

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