Question 6) Write a program to find the sum of two floating numbers in Python.
Example 1: Hardcoded Floating Points
add-two-floats.py# Program 6: Example 1
# Add two hardcoded floating points
# 1000+ Python Programs by Code2care.org
float_no1 = float('11.4')
float_no2 = float('12.4')
sum_of_floats = float_no1 + float_no2
print(f"Sum of {float_no1} and {float_no2} is {sum_of_floats}")
Output:
Sum of 11.4 and 12.4 is 23.8
Explanation:- Create a variable float_no1 and store a float value for number 1 using the float function
- Create a variable float_no2 and store a float value for number 2 using the float function
- Now, create a third variable where we add these two floats.
- Print the result using a print function with f-strings.

Example 2: Using user inputs
add-two-floats-2.py# Program 6: Example 2
# Add two user inputted floating points
# 1000+ Python Programs by Code2care.org
float_1 = float(input("Enter float 1: "))
float2 = float(input("Enter float 2: "))
sum_of_floats = float_no1 + float_no2
print(f"Sum of {float_no1} and {float_no2} is {sum_of_floats}")
Output:
Enter float 1: 10.3
Enter float 2: 10.5
Sum of 11.4 and 12.4 is 23.8
