+ 2
How i print a single list..
list=[] while True: list.append(int(input())) print(list) It's print like [1] [1,5] [1,5,8] [1,5,8,10] But I want last one..
8 ответов
+ 2
#next time pls try yourself first... Siddharth Raj
list=[]
try :
while True:
list.append(int(input()))
#when there is no input, then it raise error.
#except can handle that with how you want,
#so I just printing to continue next..
except :
print(list)
+ 7
Just change the print stmt to print(list[-1])
+ 5
Yurii Ostapenko yeah i corrected it. Thank u. Now it works fine .
+ 2
Alphin K Sajan indenting will not help since there is an infinite loop
+ 1
If you have no input then it raise error. Use try catch blocks to work it correctly...
+ 1
You're welcome..
0
Thank u..Jayakrishna😊
0
Just put a condition that if the user wants to stop input, enter some letter (something like 'n' ..)
Then using if Condition came out from the while loop and print the list .
l=list()
while True :
X=input()
if x=='n' :
break
else :
l.append(int(n))
print(l)