+ 4
multiple inputs
I want to make a calculator in Python, how would have multiple inputs?
5 Answers
+ 3
var = input().split(" ")
then you get a list of all inputs but the must be seperated with a space
+ 1
Ok, Thanks! :)
+ 1
you can also change the split("x")
then you can seperate them with x instead of space you're welcome
:)
+ 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. ;-))
+ 1
var1 = input(âenter a numberâ)
var2 = input(âenter a numberâ)
etc.