python multiple input multiple output

45 Views Asked by At

I wrote a program that gets 4 input in a line from user and it's in a loop. My problem is that if in different iterations the user want to give less than 4 input the program accept them and save them in n first variable that are in code and the program doesn't get an error

while True: 
name,arg1,arg2,arg3 = input().split()
arg2 , arg3 = int(arg2),int(arg3)
if name == "define":
    x.define(arg1,arg2,arg3)
elif name == "delete":
    x.delete(arg1)
elif name == "sell":
    x.sell(arg1,arg2)
elif name == "buy":
    x.buy(arg1,arg2)
elif name == "status":
    x.status()

elif name == "financial":
    x.financial()

elif name == "exit":
    break

else:
    print("Wrong input\a")

so for example if the user want to call the status function he must to enter 3 useless input

1

There are 1 best solutions below

0
Yaroslav M.O On

I dont understand your problem. But I modify your code:

While True: 
   try: 
      x = []
      x = input().split(' ')
      if x[0] == "define":
         x.define(x[1],x[2],x[3])
      #Rest of code
   except:
       print('Wrong input')