May-28-2018, 12:41 AM
(This post was last modified: May-28-2018, 01:23 AM by py_learner.)
Hi folks, I am new to python and having trouble to append list in for loop.. any help will be appreciated!
Its working now but still the print command works at position 1 which print after each iteration but is not printing on Position 2..(can anyone please explain why is that?)
a = [1,1,2,3,5,8,13,21,34,55,89] def less_than_ten(num): for n in a: if n < 10: print(n) less_than_ten(a) def less_than_five(num): b = [] for n in a: if n < 5: # print(n) global b.append(n) # is giving error at (.) in this line print(b) less_than_five(a)
Its working now but still the print command works at position 1 which print after each iteration but is not printing on Position 2..(can anyone please explain why is that?)
a = [1,1,2,3,5,8,13,21,34,55,89] pick_number = int(input("enter the number:")) b = [] def less_than(num): for n in a: if n < pick_number: b.append(n) print (b) #position 1 print(b) # position 2 less_than(a)