8.4k views
5 votes
Consider the following code:

start = int(input("Enter the starting number: "))
stop = int(input("Enter the ending number: "))
x = -10
sum = 0
for i in range (start, stop, x):
sum = sum + i
print(sum)
What is output if the user enters 78 then 45?

Please help me !

User FoldFence
by
4.8k points

1 Answer

5 votes

Answer:

The output is 252

Step-by-step explanation:

To get the output, I'll analyze the lines of code one after the other.

Here, user enters 78. So, start = 78

start = int(input("Enter the starting number: "))

Here, user enters 45. So, stop = 45

stop = int(input("Enter the ending number: "))

This initializes x to -10

x = -10

This initializes sum to 0

sum = 0

This iterates from 78 to 46 (i.e. 45 + 1) with a decrement of -10 in each successive term

for i in range (start, stop, x):

This adds the terms of the range

sum = sum + i

This prints the calculated sum

print(sum)

The range starts from 78 and ends at 46 (i.e. 45 + 1) with a decrement of -10.

So, the terms are: 78, 68, 58 and 48

And Sum is calculated as:


Sum = 78 + 68 + 58 +48


Sum = 252

Hence, 252 will be printed

User Miichi
by
5.3k points