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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:11:23+00:00 2026-06-13T19:11:23+00:00

I am trying to get my function to take two arguments, and return their

  • 0

I am trying to get my function to take two arguments, and return their sum. Am I going about this the right way? This is what I have so far:

def my_sum(a, b):
    sum = a + b

def main():
    a = input(int("enter a number: ", a)
    b = input(int("enter a number: ", b)

    sum = a + b

    return sum
    print(" result: ", sum)

main()
  • 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-13T19:11:24+00:00Added an answer on June 13, 2026 at 7:11 pm

    So it looks good, but the main problem is that you aren’t actually calling your function 🙂 Once you get your two numbers, you can then make the call to your function (which you have properly set up):

    def main():
        # When you assign variables here, make sure you are putting the int outside
        # You also don't need to reference the variable twice
        a = int(input("enter a number: "))
        b = int(input("enter a number: "))
    
        # Here is where your call goes (try to avoid using variable names that
        # are the same as Python keywords, such as sum)
        s = my_sum(a, b)
    
        print(" result: ", s)
    

    Now, one other thing you’ll have to do is modify your function to return a value. You’re already almost there – just add a return (note that since you are just returning the sum of the two numbers, you don’t have to assign it to a variable):

    def my_sum(a, b):
        return a + b
    

    This now means that when you run s = my_sum(a, b), your function will return the sum of those two numbers and put them into s, which you can then print as you are doing.

    One other minor thing – when you use the setup you are (with def main(), etc.), you usually want to call it like this:

    if __name__ == '__main__':
        main()
    

    At this stage, don’t worry too much about what it means, but it is a good habit to get into once you start getting into fun stuff like modules, etc. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an Excel function to return more arguments than are passed
I'm trying to get my head around this one: Say you have two models
I'm trying to get my function to return the data it got into another
Trying to get a list of all substrings currently I have a function but
I've been trying forever to get this working. The program is supposed to take
I am trying to make a swapNode function that can take any two nodes
I'm trying to create an AJAX script that will take two GET variables, class
I'm trying to take the results of a view - using the function views_get_view_result()
I am trying to get the function feedAmount to print to the console but
I'm brand new to C++ and am having trouble trying to get a function

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.