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 8841483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:43:47+00:00 2026-06-14T10:43:47+00:00

I need to be able to ask a user for a turtle command such

  • 0

I need to be able to ask a user for a turtle command such as forward(90) and execute it as a turtle command, e.g turtle.forward(90) and repeat until the user exits.
so far I have:

def turtle_input(prompt):
"""Loop to ask for user input and execute as a turtle command"""
import turtle
while True:
    t = input('Enter a turtle command: ')
    if t in ['Quit' , 'quit', 'q', 'Q']:
        break
    turtle.(t)     
return prompt
  • 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-14T10:43:48+00:00Added an answer on June 14, 2026 at 10:43 am

    executing arbitrary code is usually not a good idea as it is a huge security vulnerability, but here’s one way:

    eval('turtle.{0}'.format(t))
    

    This isn’t a good idea as consider the following string a user could pass in:

    t = 'forward(90) or __import__("os").system("rm -rf ~")'
    

    All of a sudden, your home directory starts to get deleted — Oops.


    A slightly less robust, but more secure solution might be to use ast.literal_eval and parse the string yourself:

    import ast
    
    #...
    funcname,args = t.split('(',1)
    args = ast_literal_eval('('+args)
    if hasattr(args,'__iter__'):
        getattr(turtle,funcname)(*args)
    else:
        getattr(turtle,funcname)(args)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to ask users for help if they have been
I need this to be able to ask the user for a file, then
I need to be able to create an id for a hyperlink. I have
I need to ask the user for two security questions and their corresponding answers.
I have a requirement where i need to open command prompt and run a
I need to write a program, that will ask a user to enter a
I have produced a report where the user will need to view financial years
I need to be able to have the objects within the array be valid
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.