'How to set iterations under different conditions for While loop in python?
I am quite new to codig and trying to execute the following peice of code with if conditions in while loop. The increments for w and t under if conditions do not work. Does anybody have a solution?
d=[2, 3, 2, 2, 2, 3]
c=np.empty(15)
w=0
t=0
while w<6 and t<15:
x = sum(d[:w])/(t+1)
if x==1:
c[t]=1
w+=1
t+=1
if x!=1:
c[t]=0
t+=1
Solution 1:[1]
I don't understand well what you want to do but, in line 6 (x = sum(d[:w])/(t+1)) remember that you initialized 'w' as 0, so you are not taking any sample from 'd', in consequence, 'x' will always be 0. Hope that will solve your problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrés Tello Urrea |
