altbobz1 altbobz1
  • 24-10-2021
  • Computers and Technology
contestada

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

Respuesta :

muhammadsayed06793
muhammadsayed06793 muhammadsayed06793
  • 24-10-2021

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.

Answer Link
doobthegoober doobthegoober
  • 24-10-2021
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
Answer Link

Otras preguntas

Select the correct answer Sandra works in a company which makes tomato ketchup. Her company procures tomatoes from local farmers and then uses those tomatoes fo
n = 7 * 9 i cant find the answers
The law of conservation of mass states that: O Mass can be created but energy can only be transferred O Energy can be created but mass can only be transferred M
In the reaction Mg(s) + Br2() → MgBrz(s), what should be the coefficient for Br2? A. 2 B. 4 C. 1 D. 3
How does Veterans Day differ from Memorial Day ?
What important naturalist theme is reflected in this excerpt from Stephen crane the open boat
18x + 3y = -21 !!!!!!!!!!
can anyone help me with this? it’s about the declaration of independence.
When a slope is undefined
(7th grade question pt2) If you start with 100 g, how much do you have after 30 minutes?