- 1
Plz help me. How i can use users input to make a list.
.
6 Respuestas
+ 5
First of all, please give a tag which is related to your question and topic, instead of '.' .
append() function is used to insert the number or string at last index of list . For eg ,
>>>li = [1,2]
>>>li
[1,2]
>>>li.append(3)
>>>li
[1,2,3]
>>>li.append([1,2,3])
>>>li
[1,2,3,[1,2,3]]
etc..
So, first create an empty list then decide how much number you wanna insert inside list. Then use any loop for taking input till your range use append() for adding and after your loop block will complete then you will get a list whose elements are your input which you have given.
https://code.sololearn.com/cNdcQraGis1a/?ref=app
+ 1
L=[ ]
n=int(input('Enter a range:'))
for i in range(n):
a=input() #or int(input())
l.append(a)
+ 1
ΘΟΔΩΡΗΣ ΦΕΡΕΝΤΙΝΟΣ be sure that variable which is passed in range function is a integer not a string
0
What exactly you are looking to do ? Any example input and output you can give?
0
AKSHAY🇮🇳 that's what i do. But the debugger finds an error in the range
0
AKSHAY🇮🇳 i'll try it. Thanks