jeudi 25 novembre 2021

appending an array in while loop and if condition

n = -12
while n < 15:
    if n < 0:
        dgt = []
        dgt.append(n)
    n = n+1
print(dgt)

I am trying to append all negative values in dgt[] but what I get from this code [-1] which is not my result I want all negative valuse in dgt[] please help me.

Aucun commentaire:

Enregistrer un commentaire