dimanche 5 juillet 2020

Get a list with required numbers

I need a list which has 2 up to 2095, 1 upto (2095+2932) and the rest 0.

The below code returns a list with 2 up to 2095 places and the remaining are all 1. What changes do I have to make to get 0s at the end?

target=[]
a=2095
b=2932
c=2252
x=a+b+c
for i in range(0,x):
    if (i<=a):
        target.append(2)
    elif (i>a & i<=(a+b)):
        target.append(1)
    else:
        target.append(0)

Aucun commentaire:

Enregistrer un commentaire