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

  • Home
  • SEARCH
  • 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 8943303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:44:26+00:00 2026-06-15T11:44:26+00:00

using the function below, and input which is split on space (i.e. forward 20),

  • 0

using the function below, and input which is split on space (i.e. forward 20), turtle will perform the color and write functions but using forward, back, right or left does nothing, just brings up a blank turtle window

here’s a condensed version of my functions and code for forwards and back commands:

import sys
import turtle

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
    return items_in_line



def comm(items_in_line):
    m = items_in_line[1]
    if items_in_line[0] == "forward":
        if isinstance(m,int) == True:
            turtle.forward(m)
    if items_in_line[0] == ("backward" or"back"):
        if isinstance(m,int) == True:
            turtle.back(m)

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

x = parse_line(line)

y=comm(items_in_line)
  • 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-15T11:44:28+00:00Added an answer on June 15, 2026 at 11:44 am

    Two problems here:

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

    This means "backward" will never work. Try typing this in an interactive window:

    >>> ("back" or "backward")
    'back'
    

    So, checking if something is equal to ("back" or "backward") is the same as checking if it’s equal to "back".

    You want this:

    elif items_in_line[0] in ("back", "backward"):
    

    or, if you insist, this:

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

    Then, there’s the other problem:

    if isinstance(m,int) == True:
        turtle.forward(m)
    

    Since items_in_line is the result of a split call, each element has to be a string, so it can’t possibly be an int. (Also, you shouldn’t do == True in Python, except when you specifically want to distinguish True from other true values.)

    What you may want is something like this:

    try:
        amount_to_move = int(m)
    except ValueError as e:
        print(<some message about the error>)
    else:
        turtle.forward(amount_to_move)
    

    The way your code is structured, where you do the same check in both branches of the function, it’s probably better to move it upward, so:

    def comm(items_in_line):
        try:
            m = int(items_in_line[1])
        except ValueError:
            print(<some message>)
            return
        if items_in_line[0] == "forward":
            turtle.forward(m)
        if items_in_line[0] in ("backward", "back"):
            turtle.back(m)
    

    Or maybe you don’t even need the try/except here, because you can handle it at a higher level—after all, if items_in_line only has 1 element, it’s going to raise an IndexError that you’re not catching, so why not treat "forward foo" the same way you treat "forward" and let it trickle up to the caller?

    def comm(items_in_line):
        m = int(items_in_line[1])
        if items_in_line[0] == "forward":
            turtle.forward(m)
        if items_in_line[0] in("backward", "back"):
            turtle.back(m)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below is part of an autocomplete input created using JQuery UI. But
In python I need a logic for below scenario I am using split function
I am using the function below inside a thread to receive the byte[] via
I am using the function below to open the user's default web browser. Public
First of all, i'm using the function below to read data from a pdf
Anyone experienced exception using below function? tdse.GetObject(tmpFolderWebDavURL, EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll) as Folder; Seems if
i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
I have a problem using the string function erase with iterators. The function below
I am using the below function of javascript to enable and disable the radio
I am using Serial port to receive the messages. The below function is running

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.