Answer:
sum = 0.0
for i in range(0,3):
sum += float(input("Enter a decimal number to sum: "))
print ("Sum: ", sum)
*** Sample Input ***
Enter a decimal number to sum: 1.1
Enter a decimal number to sum: 2.2
Enter a decimal number to sum: 3.3
*** Sample Output ***
Sum: 6.6
Step-by-step explanation:
For this problem, a method was devised in python to create the sum of three individual decimal numbers.
The first line of code, sum = 0.0, initializes a variable to the float type in which we will store the value of our sum. Note, it is initialized to 0.0 to start from a value of 0 and be considered a float.
The second line of code, for i in range(0,3): is the creation of a for loop control structure. This will allow us to repeat a process 3 amount of times using the iterator i, from value 0 to 3 in this case. Note, 0 is inclusive and 3 is exclusive in the python range. This means the for loop will iterate with, i=0, i=1, and i=2.
The third line of code, sum += float(input("Enter a decimal number to sum: ")) is simply asking the user for a number, taking that input and converting it from a string into a float, and then summing the value with the previous value of sum and saving that into sum.
The fourth line of code, print ("Sum: ", sum) is simply displaying the final value that was calculated by adding the three user inputs together which were stored into the variable sum.
Cheers.