0
How to take input for a list in python such that the user will input it as [1,2,3] on the screen.
4 Answers
+ 1
x= [] #here x is an empty list
for i in range(0,3):
#this will accept 3 values
n=eval(input("Enter no."))
#user will enter 1,2,3 one by one
x.append(n)
#values will be added to empty list
print(x)
0
Lst[]
n=int(input("enter no. of terms "))
for i in range(0,n):
x=int(input())
Lst.append(x)
print (Lst)
- 1
Square brackets are mandatory while providing input else it will consider input as Tuple.