Uploaded September 2024 | Updated September 2026, 1 week ago
In this video, we will learn how to write a simple Python program that adds two numbers entered by the user.
First, we’ll ask the user to enter two numbers. To do this, we’ll use Python’s built-in input() function. This function allows us to display a message on the screen, and whatever the user enters will be captured as a string. For this program, we’ll prompt the user to enter the first number. However, since the input() function returns the user’s input as a string, we’ll need to convert that string into a numeric value using the float() function. This way, the user can enter both whole numbers and decimal numbers.
Next, we’ll read the second number the same way. After converting both inputs into float numbers, we’ll perform the addition operation using the + operator and store the result in a variable. Finally, we’ll display the result to the user using Python’s print() function.
To make the output user-friendly, we’ll format it using Python’s f-string syntax, showing the equation as a string (e.g., “22.2 + 33.3 = 55.5”).
In this tutorial, you’ll see how to write a clean and simple Python program to add two numbers, with user input and formatted output. We’ll even simplify the code by removing an unnecessary variable. You’ll also see the program in action as we run it and input different values.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial
In this video, we will learn how to write a simple Python program that adds two numbers entered by the user.
First, we’ll ask the user to enter two numbers. To do this, we’ll use Python’s built-in input() function. This function allows us to display a message on the screen, and whatever the user enters will be captured as a string. For this program, we’ll prompt the user to enter the first number. However, since the input() function returns the user’s input as a string, we’ll need to convert that string into a numeric value using the float() function. This way, the user can enter both whole numbers and decimal numbers.
Next, we’ll read the second number the same way. After converting both inputs into float numbers, we’ll perform the addition operation using the + operator and store the result in a variable. Finally, we’ll display the result to the user using Python’s print() function.
To make the output user-friendly, we’ll format it using Python’s f-string syntax, showing the equation as a string (e.g., “22.2 + 33.3 = 55.5”).
In this tutorial, you’ll see how to write a clean and simple Python program to add two numbers, with user input and formatted output. We’ll even simplify the code by removing an unnecessary variable. You’ll also see the program in action as we run it and input different values.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial










