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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:36:28+00:00 2026-05-13T11:36:28+00:00

I’m new to programming and I’m interested in if it’s possible to use a

  • 0

I’m new to programming and I’m interested in if it’s possible to use a function to create another function based in inputted information:

def get_new_toy(self):
    new_toy = gui.multenterbox(
        msg = 'Enter the data for the new toy:',
        title = 'New Toy',
        fields = ('Toy Name', 'Fun for 0 to 5', 'Fun for 5 to 7', 'Fun for 7 to 10', 'Fun for over 10'))
    method = getattr(PotatoHead, new_toy[0])
    def method(self):

I don’t think that I’m doing this right

Thankful for any help

—Edit—

Sorry for not making it clear:

I’m creating a virtual pet sort of game for my younger sister.

The ‘PotatoHead’ can ‘play’ with certain toys as dictated by functions such as this:

   def play_Softball(self):
        self.happiness_num = float(self.happiness)
        if float(self.age) <= 3.0:
            self.happiness_num = self.happiness_num + 0.3
        elif float(self.age) > 3.0 and float(self.age) < 4.0:
            self.happiness_num = self.happiness_num + 0.7
        elif float(self.age) > 4.0 and float(self.age) < 7.0:
            self.happiness_num = self.happiness_num + 1.0
        elif float(self.age) > 7.0 and float(self.age) < 9.0:
            self.happiness_num = self.happiness_num + 0.5
        elif float(self.age) > 9.0:
            self.happiness_num = self.happiness_num + 0.02
            gui.msgbox(
                msg = 'This toy is Only providing minimal fun to your potato head. Either get a new one or play with another!',
                title = 'WARNING!',
                ok_button = 'Understood')
        self.happiness = str(self.happiness_num)

I want there to be a function that allows the creation of a new ‘toy’ as a function that is similar to the one above.

Again, thanks for any help

—UPDATE—

Thanks again, but just wondering

Is it possible to work something such as this into it:

'play_' + new_toy[0] = myPotatoHead.create_toy(new_toy[1], new_toy[2], new_toy[3], new_toy[4], new_toy[5])

in this context:

    def get_new_toy(self):
        new_toy = gui.multenterbox(
            msg = 'Enter the data for the new toy:',
            title = 'New Toy',
            fields = ('Toy Name', 'Fun for 0 to 3', 'Fun for 3 to 4', 'Fun for 4 to 7', 'Fun for 7 to 9', 'Fun for over 9'))
        'play_' + new_toy[0] = myPotatoHead.create_toy(new_toy[1], new_toy[2], new_toy[3], new_toy[4], new_toy[5])
        self.toys.append(new_toy[0])

thanks again for any help

  • 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-05-13T11:36:28+00:00Added an answer on May 13, 2026 at 11:36 am

    Here is an example python function that returns a new function based on the parameter passed in. I’m not sure what you are trying to do but this might help point you in the right direction.

    def add_to(amount):
        def f(x):
            return x + amount
        return f
    
    if __name__ == "__main__":
        add_2 = add_to(2)
        add_3 = add_to(3)
    
        print add_2(42)
        print add_3(42)
    

    Given your toy example (which seems like a fun thing to do for you sister) you might try something like this (I haven’t tested the code, but it should help out):

    def create_toy(self, fun_0_3, fun_3_4, fun_4_7, fun_7_9, fun_9_plus):
        def toy(self):
            self.happiness_num = float(self.happiness)
            if float(self.age) <= 3.0:
                self.happiness_num = self.happiness_num + fun_0_3
            elif float(self.age) > 3.0 and float(self.age) < 4.0:
                self.happiness_num = self.happiness_num + fun_3_4
            elif float(self.age) > 4.0 and float(self.age) < 7.0:
                self.happiness_num = self.happiness_num + fun_4_7
            elif float(self.age) > 7.0 and float(self.age) < 9.0:
                self.happiness_num = self.happiness_num + fun_7_9
            elif float(self.age) > 9.0:
                self.happiness_num = self.happiness_num + fun_9_plus
                gui.msgbox(
                    msg = 'This toy is Only providing minimal fun to your potato head. Either get a new one or play with another!',
                    title = 'WARNING!',
                    ok_button = 'Understood')
            self.happiness = str(self.happiness_num)
        return toy
    
    #somewhere else
    play_Softball = create_toy(0.3, 0.7, 1.0, 0.5, 0.02)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.