0

Python input

Guys how can we take input in a row in python?

9th Sep 2020, 6:42 PM
Lisanewerk Mikiyas
Lisanewerk Mikiyas - avatar
5 Answers
+ 7
Lisanewerk Mikiyas , do you want to take a multiple input in one go with input() like: 2, 4, 11, 0 / or could also be string, ... If not, please be so kind and create a sample of input value, and what do you want to output. Thanks!
9th Sep 2020, 6:53 PM
Lothar
Lothar - avatar
+ 5
If you want to input more than 1 value, it can be done like this. The values from input will be integer and are stored in a list: You can use an input with split, map and int conversion or a list comprehension with int conversion: (1) input with split(), int conversion: inp = list(map(int, input('').split())) # input like: 1 3 12 (2) input with split(), int conversion and comprehension: inp = [ int(i) for i in input().split()] # input like: 1 3 12 Both versions have the result of: [1,3,12]
13th Sep 2020, 7:59 PM
Lothar
Lothar - avatar
+ 1
I dont think I understand, can you explain or provide an example?
9th Sep 2020, 6:48 PM
Steven M
Steven M - avatar
+ 1
Steven M i mean how could we take multiple input in a single line from the user.... For example: Height=input() This accepts one height variable....my question is how could we take multiple inputs with space separated in the single line
13th Sep 2020, 7:41 PM
Lisanewerk Mikiyas
Lisanewerk Mikiyas - avatar
+ 1
Lothar thanks i need that exact answer
24th Sep 2020, 7:49 AM
Lisanewerk Mikiyas
Lisanewerk Mikiyas - avatar