Introduction
In this post, you will learn how to add two numbers in python and also how to get the user value and add two values and below is the video format of the post, check it out.
Video:
How to add two numbers in python
To add two numbers in python we need to know about,
Input function: Allows the user to input the value.
Data type: We will be using str and int data types and also float.
Operators: There are different operators we will be using + and =
F-string: The f-string allows the final print statement to be meaningful.
Adding two numbers manually ????????
The result ????????, You can add the values you want…
![Adding two numbers in python](http://techyrick.com/wp-content/uploads/2021/10/2021-10-19-20_49_41-Thonny-C__Users_moulik_Documents_ddd.py-@-10-_-41.webp)
Let’s add some there values in the place of a and b and see what we get in the place of c, And also instead of c you can add a meaning full variable like value = a +b
Let’s add float values in the place of a nad b.
Float values are nothing but decimal values.
The result will be something like this ????????
![Adding two numbers in python](http://techyrick.com/wp-content/uploads/2021/10/2021-10-19-20_55_56-Thonny-C__Users_moulik_Documents_ddd.py-@-3-_-9.webp)
Adding two numbers by user input
Here, We have added the input function so, that we get the input from the user and also you may notice I have added int function.
The int function adds up the value, without int you will not get added up normally.
Instead of int function, you can add float in front, So, that you get the output values in decimal.
And then I added another variable, where the value a and b will be saved there and finally I have entered the print function, For a more meaningful sentence I have added the f-string.
The result ????????
![Adding two numbers in python](http://techyrick.com/wp-content/uploads/2021/10/2021-10-19-22_04_35-Thonny-C__Users_moulik_Documents_ddd.py-@-6-_-53.webp)
* Remember if you want the output values in decimal, you need to add float instead of int
Also Read: Python pizza ordering project
Also Read: Leap year in python full tutorial