116k views
13 votes
What is the output of this program?

numA = 2

for count in range(5,8):

numA = numA + count

print(numA)

Output:

User Verix
by
5.3k points

2 Answers

10 votes

Answer:

20

Step-by-step explanation:

assuming the print statement is not indented, the program effectively calculates 2+5+6+7.

The range(...) is excluding the end value (8 in this case).

User Nicholas Farmer
by
5.0k points
12 votes

Answer:

The output is 20

Step-by-step explanation:

Given:

numA = 2

for count in range(5,8):

numA = numA + count

print(numA)

Required:

Determine the output

The first line of the program initializes numA to 2.

The next iteration sum up integers from 5 to 7 (i.e. 8 - 1) to the initialized value of numA

So, numA becomes


numA = 2 + 5 + 6 + 7


numA = 20

Hence, the output is 20

User Paul Joireman
by
5.5k points