144k views
5 votes
What is the value of x after running this code?

x = 0
for y in [1,2,3,4,5,6,7,8,9,10]:
x = x + y

2 Answers

2 votes
When the code runs it sums up the numbers, which results in 55. It says AFTER the code is finished so the answer will be 55. You can verify this by printing X again after the for loop
User Deasserted
by
3.3k points
4 votes

counter = 1

sum = 0

while counter <= 6:

sum = sum + counter

counter = counter + 2

print(sum)

A. 12

B. 9

C. 7

D. 8

✔️ Correct! This loop executes 3 times. After the first loop sum = 1 and counter = 3, after the second loop sum = 4 and counter = 5, and after the third loop sum = 9 and counter = 7.

User Iamhuynq
by
3.3k points