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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:32:15+00:00 2026-06-12T08:32:15+00:00

I was trying to make a game in Python where the user inputs a

  • 0

I was trying to make a “game” in Python where the user inputs a command. However, I do not know whether you can take that input to be a function name. This is my current effort:

def move():
    print("Test.")

if __name__ == "__main__":
    input("Press enter to begin.")
    currentEnvironment = getNewEnvironment(environments)
    currentTimeOfDay = getTime(timeTicks, timeOfDay)
    print("You are standing in the {0}. It is {1}.".format(currentEnvironment, currentTimeOfDay))
    command = input("> ")
    command()

Here, the input was move, as I wanted to try and call that function (as a potential end user might). However, I get the following error:

Traceback (most recent call last):
  File "D:\Text Adventure.py", line 64, in <module>
    command()
TypeError: 'str' object is not callable

I was wondering if there was any way that I could allow a user to ‘move’ in the game, which the program achieves by calling the “move” function.

  • 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-12T08:32:16+00:00Added an answer on June 12, 2026 at 8:32 am

    It looks like you’re using python3.x where input returns a string. To recover the python2.x behavior, you need eval(input()). However, you shouldn’t do this. It’s likely to lead to a bad day.


    A better idea is to put the functions into a dictionary —

    def move():
        #...
    
    def jump():
        #...
    
    function_dict = {'move':move, 'jump':jump }
    

    and then:

    func = input('>')  #raw_input on python2.x
    function_dict[func]()
    

    The following code works for me on python3.2.

    def move():
        print("Test.")
    
    func_dict = {'move':move}
    if __name__ == "__main__":
        input("Press enter to begin.")
        currentEnvironment = "room" #getNewEnvironment(environments)
        currentTimeOfDay = "1 A.M." #getTime(timeTicks, timeOfDay)
        print("You are standing in the {0}. It is {1}.".format(currentEnvironment, currentTimeOfDay))
        command = input("> ")
        func_dict[command]()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a small game that supports Python scripting. I've no problems
I am trying to make a game object that can be made semitransparent during
I am trying to make a textual game in python. All goes well however,
Trying to make simple minesweeper game in python, but have one problem. I have
I am trying to make some game, I'm not going to explain what is
Trying to make an xna game, where the user needs to tap to stop
I'm trying to make a game (using irrlicht engine with c++) where you can
I'm trying to make a game where the user is supposed to drag a
I'm trying to make an android game here, but I'm not sure what is
Im trying to make a game for the iPhone that has background music. So

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.