multiple inputs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

multiple inputs

I want to make a calculator in Python, how would have multiple inputs?

22nd Oct 2018, 7:58 PM
Tyler
Tyler - avatar
5 Answers
+ 3
var = input().split(" ") then you get a list of all inputs but the must be seperated with a space
22nd Oct 2018, 8:01 PM
Mbrustler
Mbrustler - avatar
+ 1
Ok, Thanks! :)
22nd Oct 2018, 8:02 PM
Tyler
Tyler - avatar
+ 1
you can also change the split("x") then you can seperate them with x instead of space you're welcome :)
22nd Oct 2018, 8:04 PM
Mbrustler
Mbrustler - avatar
+ 1
You can also take each input separately by looping and saving the results in a list, for example: L=[] while True: number=input() if not number: break if number.isdigit(): L.append(int(number)) Like that you are flexible in how many inputs you take - it stops when the user just presses enter. (Taking input with a loop works well in real life, not on sololearn though. ;-))
22nd Oct 2018, 11:10 PM
HonFu
HonFu - avatar
+ 1
var1 = input(“enter a number”) var2 = input(“enter a number”) etc.
24th Oct 2018, 9:23 AM
Rohan