Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:30:19+00:00 2026-06-15T10:30:19+00:00

running a program I am making to draw with turtle graphics, I put in

  • 0

running a program I am making to draw with turtle graphics, I put in an exit command, however now whenever I enter any single-word commands I get an indexerror (IndexError: list index out of range) at the elif for the “back” command:

def parse_line(line):
    global items_in_line
    items_in_line = line.split(" ",1)
    if items_in_line[0] == "forward":
        if isinstance(items_in_line[1], int):
                return items_in_line
    elif items_in_line[0] == "back" or "backward":
        if isinstance(items_in_line[1], int):
             return items_in_line
    ...
    elif items_in_line[0] == "exit":
        sys.exit()

line=input("Enter a turtle command or enter 'file' to load commands from a file")

x = parse_line(line)

Why? and how can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:30:20+00:00Added an answer on June 15, 2026 at 10:30 am
    elif items_in_line[0] == "back" or "backward":
    

    the above condition is equivalent to: –

    elif (items_in_line[0] == "back") or "backward":
    

    Which will always be evaluated to true, and thus will also be executed if you pass “exit” as input, and hence items_in_line[1] will throw IndexError.

    You need to change the condition to: –

    elif items_in_line[0] in ("back", "backward"):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a command line program in C using XCode. When running the
I now have a running Java program which only lacks of the final step,that
now.. I was making a program.. but I want to make the program connected
Right, I'm running Drools in a ordering program I'm making. I was asked to
I just got a semi function head program running and I need help making
I am currently making a program with the AWT GUI and I'm running into
This C program I am making reads a set of chars from the command
I am looking for a method to monitor a running program that I have
I'd like to break out of the currently running program and be dropped back
Running this program is printing forked! 7 times. Can someone explain how forked! is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.