0

#python# How do you receive one list or some numbers from users?

#python#I want to recieve one list or more than one data, how should I use input function for that in python?

23rd Mar 2020, 3:53 PM
mohammad amin soltani
mohammad amin soltani - avatar
23 Answers
+ 4
mohammad amin soltani int(input()) for a number but if u want that each number he inputs like 123765 and u want to convert them into a list, so u can do it by using split. int(input()).split() Now it would turn into [1,2,3,7,6,5] If they have spaces in them like 1 2 3 7 6 5 in input then change ur code a bit and add a space in split like, int(input()).split(" ") so that it splits all the items aside of spaces into a list.
23rd Mar 2020, 4:21 PM
maf
maf - avatar
+ 3
For getting average of your list you can try the following code: n=eval(input("Enter List :")) m=len(n) print("Average of list:", sum(n)/m)
23rd Mar 2020, 5:12 PM
ANJALI SAHU
+ 3
I’m not sure I got what you want to do, but you can try this print(list(input()))
25th Mar 2020, 2:08 PM
Douglas
+ 2
Mohammad amin soltani If you want to input list you can use eval function... n=eval(input("Enter list:")) #[2,5,7,8, 9] And if integer then n=int(input("Enter no.:"))
23rd Mar 2020, 5:08 PM
ANJALI SAHU
+ 2
Great! You are professional
23rd Mar 2020, 5:22 PM
mohammad amin soltani
mohammad amin soltani - avatar
+ 2
🙂😄👍 I am also learning Python ...
23rd Mar 2020, 5:25 PM
ANJALI SAHU
+ 1
If user enter 100 the output is 99 98 97 ............etc .. CHECK this code ... https://code.sololearn.com/cpQFmIcKvhj4/?ref=app
25th Mar 2020, 4:42 AM
Syed Ahmed Raza Shah
Syed Ahmed Raza Shah - avatar
0
How?
23rd Mar 2020, 4:03 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
Thank you, but I want to recieve one list, can I want user to intern his list?and if you say yes tell me how, please.
23rd Mar 2020, 4:09 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
Okay, thank you.
23rd Mar 2020, 4:13 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
Whoops?
23rd Mar 2020, 4:14 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
Infact I want to write a code that give the user average of his list .
23rd Mar 2020, 4:17 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
Thanks
23rd Mar 2020, 4:41 PM
mohammad amin soltani
mohammad amin soltani - avatar
0
PsychoPython loll no man, just on an intermediate lvl, thnx tho
23rd Mar 2020, 4:43 PM
maf
maf - avatar
0
If data type is int() use int(input()) following the former if input has have certain separators use int(input).split("separator") to pack them in list form ,in case of data type string use input() directly rest same as int() to collect in form of list
25th Mar 2020, 7:36 AM
Neel Kamal
Neel Kamal - avatar