dimanche 4 avril 2021

While loop for more than one Condition [closed]

How can I change from If.. elif Loop to a While True Loop lets say i have a list/Array which have different values example!

x=np.arrange[0,2,0.5]
Counted = [ 0 for x in range(21)]

instead of typing the Range manually like

if 0<x>0.5 then  counted [0]+=1
elif 0.5<x>1 then  counted [1]+=1

this might take in some other scenarios ages to write.

I thought of doing it using the For and While True loop but I don't know how can I do the interval/condition changes dynamically without changing it everytime myself.

Aucun commentaire:

Enregistrer un commentaire