94,856 views
18 votes
18 votes
What is the output of this program? Assume the user enters 3, 6, and 11.

numA = 0
for count in range(3):
answer = input ("Enter a number: ")
fltAnswer = float(answer)
numA = numA + fltAnswer
print (numA)

User ATNASGDWNGTH
by
3.1k points

1 Answer

11 votes
11 votes

Answer: 20

That would be the sum of 3, 6 and 11.

Step-by-step explanation:

numA = 0

This step creates a variable called num A with the value of zero.

for count in range(3):

This step repeats our following 3 lines of code 3 times.

answer = input ("Enter a number: ")

This line of code creates and sets the variable "answer" to the

value of what the user enters.

fltAnswer = float(answer)

This step converts our prevous user input which was a string into a

float. This is were the code screams if you were to enter a character

instead of a number.

numA = numA + fltAnswer

This step adds the user input to the variable numA.

Or more correct:

This step sets the variable numA to its previous value plus the user

input.

print (numA)

This step prints out numA. This line is also outside of the loop and

will only activate once when the loop ends.