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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:41:29+00:00 2026-05-18T06:41:29+00:00

Hi there First of all just let me say that I’m new in Python

  • 0

Hi there
First of all just let me say that I’m new in Python and this is for a school work so this should be done without advanced programing and global functions. Using Python 2.6.6 and WingIDE 101

I need a program to present the user with a menu. The user must pick an option and accordingly to is pick the program does what the user wants.

For example, in the code bellow (its not the actual code), if the user picks 1 it goes to the sum() function.

def menu():
    print "What do you want? "
    print " 1 for sum"
    print " 2 for subtraction"
    pick = raw_input("please insert 1 or 2 ")
    if pick == "1":
       return sum()
    if pick == "2":
       return subtraction()
    else:
        menu()
menu()

def sum():
    return 8 + 4
def subtraction():
    return 8 - 4

I what to know how do I send, after my pick, the program to execute an determined definition.

Thanks

P.S. – running this gives me this error:
Traceback (most recent call last):
File “/usr/lib/wingide-101-3.2/src/debug/tserver/_sandbox.py”, line 12, in
File “/usr/lib/wingide-101-3.2/src/debug/tserver/_sandbox.py”, line 7, in menu
TypeError: sum expected at least 1 arguments, got 0

  • 1 1 Answer
  • 2 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-18T06:41:29+00:00Added an answer on May 18, 2026 at 6:41 am

    There are lots of things wrong with this, so we will take up one by one.

    sum is a built-in function in Python. So you cannot name your function sum. You have to call yourself something else, like sum_foo. Or _sum.

    Also, your code is executed from top to bottom. So if you are calling a function say X in a function like Y.

    def f():
            y()
    f()  
    def y():
            print 'Y called'
    

    Results in this error:

    NameError: global name 'y' is not defined
    

    Because at your program runs, it is not aware of y because the y has not been declared at that point, since the program jumps to f().

    To fix this, you would do:

    def f():
            y()    
    def y():
            print 'Y called'            
    f() 
    

    Also, call the function as func_name() and not return func. And since in your sum and subtraction, you are returning the values, save them in some variable and print them, or print them directly.

    def sum():
        return 8 + 4
    

    No output

    def sum():
        print 8 + 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all let me just say that I am new to nHibernate so
first of all please let me say that I am quite new to objective
First of all, let me just say that I'm using the PHP framework Yii,
First let me say that I have been working on this issue for about
Just a very general question, that not only applies to this example. Let's say
First of all I want to say that I'm completely new to maven. So
First of all there is probably a question like this already but i couldn't
First of all: I do know that there are already many questions and answers
I'm wondering if there's a reason that there's no first(iterable) in the Python built-in
First, let me say that I am aware of the cons of using recursive

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.