lundi 4 janvier 2021

I have writen this code but I don't understand why it works like this

I have a code, It gets a number as n for the amount of number you want to give, then I have another input which is the numbers we want to give the code, I want my code to find the numbers lower than 3 and produce the output but it works pretty weirdly! so help me people, Thx a lot in advance

y = []
n = int(input())
for i in range(1,n+1):
    x = input()
    x = x.split()
    
    for j in x:
        j = int(j)
        if j < 3:
            for j in x:
                y.append(j)
                break
            print(y)

my input is like : 5 1 2 3

my output should be : 1 2

but it is like : ['1','1']

Aucun commentaire:

Enregistrer un commentaire