Sum of Two Numbers In Python or Adding Two Numbers

This article is an easy way to Print the Sum of Two Numbers In Python. This code will dynamically sum the 2 given numbers when the user clicks on the calculate button.

How To Print Sum Of Two Numbers using Python: Project Information

Project Name:How To Print Sum Of Two Numbers Python Project
Language/s Used:Python (GUI) Based
Python version (Recommended):2.x or 3.x
Database:None
Type:Python App
Developer:IT SOURCECODE
Updates:0
How To Print Sum Of Two Numbers using Python – Project Information

The code uses the Tkinter module to create a layout and widgets that may call specific Python functions.

About The Project

We will be the usage of Python programming language because it’s widely used as an advanced-degree programming language for a general approach to the developer. This tutorial also includes the downloadable Sum of 2 Numbers In Python source code.

To start creating How To Print Sum Of Two Numbers, make sure that you have Pycharm IDE installed on your computer.

By the way, if you are new to Python programming and don’t know what Python IDE to use, I have here a list of the Best Python IDE for Windows, Linux, and Mac OS that will suit you.

I also have here How to Download and Install the Latest Version of Python on Windows.

How To Add or Sum of Two Numbers In Python With Source Code

How To Print Sum Of Two Numbers With Source Code

  • Step 1: Create a project name.

    First step open Pycharm IDE and click “file.” After that create a project name and then click the “create” button.
    Sum of Two Numbers Create Project

  • Step 2: Create a python file name.

    Second step “right-click” your project name folder and choose new and then click “python file“.
    Sum of Two Numbers Create Python File

  • Step 3: Name your python file.

    Third step name your Python file and click “enter” to start creating on How To Print Sum Of Two Numbers
    Sum of Two Numbers Python File Name

  • Step 4: The actual code.

    The fourth step is the actual coding of How To Print the Sum Of Two Numbers.

Python Program To Add Two Numbers Code Explanations

1. Import Tkinter

The code given below is for importing tkinter modules.

from tkinter import *
from tkinter import messagebox

Importing the tkinter modules.

2. GUI Design

The code given below is for the GUI design.

        def check():



                    self.label1 = Label(self, text="Enter Number 1" ,  fg = 'black', font=("courier-new", 18, 'bold'))
                    self.label1.place(x=280, y=180)
                    self.num1 = Entry(self, textvariable=self.a,bg='light blue', width=45)
                    self.num1.place(x=480, y=190)
                    self.label2 = Label(self, text="Enter Number 2" , fg = 'black', font=("courier-new", 18, 'bold'))
                    self.label2.place(x=280, y=250)
                    self.num2 = Entry(self, textvariable=self.b,bg='light blue', width=45)
                    self.num2.place(x=480, y=255)
                    self.butt = Button(self, text="Calculate",bg ='green', font=10, width=8, command=chex).place(x=580, y=300)
                    self.label3 = Label(self, text="Sum of Two Numbers", fg='black', font=("courier-new", 24, 'bold'))
                    self.label3.place(x=380, y=30)

This module which is the design of this project uses Graphical User Interface (GUI).

Output:

Sum of Two Numbers Output
Sum of Two Numbers Output

3. Calculate Two Numbers

The code given below is for calculating the two numbers.

        def chex():
            if not self.num1.get() and not self.num2.get():
                print("Please enter a number")
            else:
                res = int(self.num1.get()) + int(self.num2.get())
                messagebox.showinfo('Sum of Two Numbers', "The answer is: %d" % (res))
                self.num1.set = ""
                self.num2.set = ""

This module calculates the two input numbers in addition.

Output:

Calculate Two Numbers in Python
Calculate Two Numbers in Python

Complete Source Code

from tkinter import *
from tkinter import messagebox

#creating window
class Lib(Tk):
    def __init__(self):
        super().__init__()
        self.a = StringVar()
        self.b = StringVar()
        self.maxsize(1200, 700)
        self.minsize(1200, 700)
        self.configure(bg="white")
        self.title("Sum of Two Numbers by: IT SOURCECODE")


#verifying input
        def chex():
            if not self.num1.get() and not self.num2.get():
                print("Please enter a number")
            else:
                res = int(self.num1.get()) + int(self.num2.get())
                messagebox.showinfo('Sum of Two Numbers', "The answer is: %d" % (res))
                self.num1.set = ""
                self.num2.set = ""


        def check():



                    self.label1 = Label(self, text="Enter Number 1" ,  fg = 'black', font=("courier-new", 18, 'bold'))
                    self.label1.place(x=280, y=180)
                    self.num1 = Entry(self, textvariable=self.a,bg='light blue', width=45)
                    self.num1.place(x=480, y=190)
                    self.label2 = Label(self, text="Enter Number 2" , fg = 'black', font=("courier-new", 18, 'bold'))
                    self.label2.place(x=280, y=250)
                    self.num2 = Entry(self, textvariable=self.b,bg='light blue', width=45)
                    self.num2.place(x=480, y=255)
                    self.butt = Button(self, text="Calculate",bg ='green', font=10, width=8, command=chex).place(x=580, y=300)
                    self.label3 = Label(self, text="Sum of Two Numbers", fg='black', font=("courier-new", 24, 'bold'))
                    self.label3.place(x=380, y=30)


        check()

Lib().mainloop()

Downloadable Source Code

I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.

Summary

This article How To Print Sum Of Two Numbers In Python is designed in Python programming language, because it’s widely used as an advanced-degree programming language for a general approach to the developer.

This simple project is a way to help beginners or students in declaring modules, variables, and many more, and also help to enhance and develop their logical skills in programming.

Inquiries

If you have any questions or suggestions about How To Print the Sum Of Two Numbers In Python, please feel free to leave a comment below.

Frequently Asked Questions

What does this Python tutorial cover?

Focused Python language or library tutorial showing a single concept with working code. Use as building block when assembling a larger system.

What Python version and libraries does this project require?

Most projects in this batch use Python 3.10, 3.11, or 3.12 (avoid 3.13 until library wheels catch up). Standard libs: tkinter (built-in), sqlite3 (built-in). External: pip install pillow opencv-python pygame mysql-connector-python reportlab requests beautifulsoup4. Check the requirements.txt file (if included) for exact versions.

How do I set up the database for this Python project?

For SQLite (most common, no setup needed): the .db file auto-creates on first run. For MySQL: install MySQL Server + MySQL Workbench, create an empty database, import the included .sql file, edit the connection string in db.py (or db_connect.py) with your host, user, password, database name.

Can I use this Python project for a BSIT capstone or thesis?

Yes. Python is rising fast in Philippine BSIT panels. Extend it: add user roles via auth module, dashboards (matplotlib charts), PDF reports (reportlab), email notifications (smtplib), real domain extension (analytics, audit log, multi-branch support). Pair with Chapter 1-5 documentation matching your panel’s rubric.

Why am I getting ‘ModuleNotFoundError’ or ‘No module named X’?

Three common Python issues: (1) Module not installed: pip install (use pip3 on macOS/Linux). (2) Wrong virtualenv: activate the project’s venv before running (python -m venv venv then venv\Scripts\activate on Windows or source venv/bin/activate on Linux/macOS). (3) Python 2 vs Python 3 mismatch: ensure you run python3 main.py not python main.py if both are installed.

Where can I find more Python projects with source code?

Browse the Python Projects hub for the full library. For computer vision specifically see OpenCV Projects (46 vision systems). For ML / AI capstones see Machine Learning Projects. For BSIT capstone idea lists see 150 Best Capstone Project Ideas.

Angel Jude Suarez

Full-Stack Developer at PIES IT Solution

Focuses on Python development, machine learning, and AI integration. Has built production AI systems including OpenAI Whisper integration for medical transcription and GPT-4o-powered diagnosis assistance. Strong background in pandas, scikit-learn, and TensorFlow.

Expertise: Python · PHP · Java · VB.NET · ASP.NET · Machine Learning · AI Integration · OpenCV · Django · CodeIgniter  · View all posts by Angel Jude Suarez →

Leave a Comment