+ 1
While loop
i=1 while True: if i%3==0: break print([i],end=" ") i=i+1 --------------------------- I am getting 2 diff lists in output. But I want only one list. What should I change in the code?
3 Respostas
+ 4
Have an empty list prepared, then append <i> into it as the loop iterates. Print the list after loop completed.
i, l = 1, []
while True:
if i % 3 == 0:
break
l.append(i)
i += 1
print(l)
+ 3
You can do this too.
i = 1
a = []
while True:
if i%3 == 0:
break
a += [i]
i += 1
print(a)
+ 3
That means I dont need to print "i", instead append i's values in diff list.. Thnks anyways