0

# While Loops

Can someone please explain this problem to me? z = 2 sum = 0 while z<9: z += 1 sum=sum+z print (sum) Thanks

11 Answers

+ 3

You havent declare variable m and total, before the loop

0

Oh sorry I typed in the wrong one

0

z = 2
sum = 0
while z<9:
z += 1
sum=sum+z
print (sum)

0

Whats wrong with that ?

0

Nothing is, I just don’t know how you get the output

0

Can you please explain it to me?

0

Try adding this line
print(str(sum)+"+"+str(z))
Inside the loop :D

0

The answer is 42. I just wanna know how to get to it because I have this worksheet with a bunch of while loops problems but I don’t know how to do them without checking with python. Could you please show me the steps to it?

0

z = 2
sum = 0
while z<9:
print("z:",z,"\nsum:",sum,"\nz+=1: ", z+1, "\nsum+z: ",sum+(z+1),"\n----\n")
z += 1
sum=sum+z
print (sum)

0

???? I don’t get it :/

0

Try to run the code, each step will be printed

Hot today

Bug: Sololearn notification is still showing number in the notification icon even i did mark as read

6 Votes

Web development

2 Votes

Finished python for beginners

1 Votes

Izzy the iguana code coach

0 Votes

C++ Question re stringstream

0 Votes

Why sometimes 0 is printed?

0 Votes