How to add two float numbers in Python


Let's see how we can add two float numbers in Python using a program.

# Code2care Python Programming:
# Add two float numbers
# in Python

float_number_1 = float(10.97)
float_number_2 = float(11.13)

sum_of_two_float_numbers = float(float_number_1 + float_number_2)

print('Sum: {0} + {1} = {2}'.format(float_number_1, float_number_2, sum_of_two_float_numbers))

PyCharm Output:
/Users/code2care/.local/share/virtualenvs/examples-E9HN9Crc/bin/Python /Users/code2care/PycharmProjects/examples/main.py
Sum: 10.97 + 11.13 = 22.1

Process finished with exit code 0

Python Program add two Floats
Python Program add two Floats
  1. Create a variable float_number_1 that holds the first floating number,
  2. Create a variable float_number_2 that holds the second floating number,
  3. Now create a variable sum_of_two_float_numbers that holds the sum of the two numbers.
  4. Make use of the + Operator to add two floats,
  5. Print the sum in console using print method.


Have Questions? Post them here!
Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap