- 2

python how to take multiple inputs from user in function ?

how to take multiple inputs from user in function. How i can take Multiple i.e may be user enter 2 input or 3 input etc from user using variable length argument.

15th Dec 2019, 5:05 PM
Tirath Sharma
Tirath Sharma - avatar
4 Answers
+ 1
You can use a comprehension for input a various number of values: # multiple input with comma as separator. No loop needed. Does convert input to integer. Variable number of inputs without changing the code. res = [int(i) for i in input("Enter multiple value: ").split(',')] print(res) #If no conversion to int is needed you can use this: res = [i for i in input("Enter multiple value: ").split(',')] print(res)
15th Dec 2019, 6:06 PM
Lothar
Lothar - avatar
0
I am asking for variable length argument these all are basics.
19th Dec 2019, 9:36 AM
Tirath Sharma
Tirath Sharma - avatar
0
Lothar what if these inputs are assign to variables.can this your approach be used.
12th Dec 2021, 7:07 PM
Sunday Olorunfemi
- 1
You can use the while loop to take multiple user inputs. For instace: flag = True while flag: user_input = int(input('enter number: ')) repeat = input('do you want to continue (y/n): ') if repeat == n: flag = False
15th Dec 2019, 5:37 PM
Fidelis Musamba
Fidelis Musamba - avatar