Computer Science, asked by kadamsidharth8, 5 months ago

What is the output of the below code snippet?
X=0
for y in range(21):
X+=y
print x

Select one:

a. Error

b. Sum of numbers up to 20(including)

c. Sum of numbers up to 21(including)

d. None of the Above​

Answers

Answered by Anonymous
1

Answer:

the output of the below code snippet is error

Explanation:

please make me brainliest ✌️

Answered by vishakasaxenasl
0

Answer:

The output of the code will be an option (b)

b. Sum of numbers up to 20(including)

Explanation:

Given Code Snippet

X=0

for y in range(21):

X+=y

print x

Let's try to understand the code.

  • First, x is an integer variable having an initial value of 0.
  • Then we have a for loop here that works in the range of 21.
  • This for loop will start from 0 by default since no starting point is specified explicitly.
  • Then it is incremented by one automatically till we reach the endpoint in every iteration.
  • Later, 21 is given as the endpoint. That means the for loop will end one point before the 21. So we reach 20 only.
  • Since we are adding every value of y with x. This way we are calculating the sum from zero to 20.
  • When the loop is terminated this sum is printed as the output.
  • Hence, the code snippet gives us a Sum of numbers up to 20(including) and option(b) is correct.

#SPJ2

Similar questions