Python Program to Add Two Numbers

Here you will get the simplest way to add two numbers in python by using the + operator. The program will first ask the user to enter two numbers, calculate their sum, and finally print it.

input() is an inbuilt function that is used to take input from the user.

Example 1: Without Using Function

In this example, we do not define any function. We are directly adding the numbers and then printing the result.


enter first number:5
enter second number:7
sum: 12

Example 2: Using Function

In this example, we will create a user-defined function sum(). It will take two numbers as arguments and return their sum.


enter first number: -4
enter second number: 5
sum: 1

Video Tutorial

Here is the video that will help you learn the concept easily.

Need Python Programming Help? Visit, they have expert python programmers available 24*7.

Python programming is an essential skill for many computer science fields.

However, it can be challenging to learn and complete programming assignments on your own. That’s why Python assignment help is available to make programming easier and less stressful.

Comment down below in case you are getting any problems with the sum of two numbers in python. You can also share your feedback or any queries.

15 thoughts on “Python Program to Add Two Numbers”

  1. Hiii am Arun student of Computer science means programmer plz help me am now biginner programmer but I take intereste in Programming world .But I don’t have any Senior and Coach .
    Can you help me

    1. Sure if you are going with programming you need to start from somewhere and i believe since you are cse students so you must be knowing oop so better is to start with java core and after that you will get an idea how and where to go. Perhaps with python ruby big data java script or anything you like

  2. Thanks so much, Neeraj! I really appreciate you helping out us fellow programmers with our coding, even though you don’t have to! 🙂

  3. We need
    Nested For Loops
    Nested While Loop
    Function (1)
    Nested if
    If else if

    Just an examples with minimun 15 lines of codes

  4. Thank you developer of this site. This helped me a lot. Now I don’t have any problem in programming anymore. 👍🏻👍🏻👍🏻

  5. Good day, I am learning Python programming, I have been asked to”
    Write a Python function Sum() to add two numbers
    For example:
    Test Result
    print(Sum(1,1)) 2
    print(Sum(1,2)) 3
    print(Sum(1,3)) 4

    This is the code which I wrote:

    However, when I try to submit my results, I get the following answer:
    ***Run error***
    Traceback (most recent call last):
    File “__tester__.python3”, line 13, in
    NameError: name ‘Sum’ is not defined

    Please assist on how I can fix this error.

  6. @Hilda coombe
    you have not defined Sum anywhere. for ur given question u can try the following ways. (I am a beginner too)

    def Sum(a,b):

    #OR Other Way

    a=int(input(“please enter 1st value :”))
    b=int(input(“please enter 12nd value :”))
    def Sum(a,b):

Leave a Comment

Your email address will not be published. Required fields are marked *