+ 1
Can someone explain this answer?
2 Respostas
+ 1
Let the way for the level 3 guy 😌😂
You demand to print k ,which has a last value of k*n .and this precedent k=1 ,while n is in the interval :[1,2,3,4]
So k=k*n =1*1 and then the new k(0)=1 too..
The loop repeat the operation with every new value of n :
K(1)=k(0)*2=2
K (2)=k (1)*3=6
K (3)=k (2)*4=24 (the end of while loop)
Your code is:
n=1
k=1
while n <=4:
k *=n
n +=1
print(k)