How to take multiple input (string,integer,integer) in Python 3





n=int(input())
num=[]
for i in range(0,n):

    op=input().split()  #Take multiple input as a list by split(). 1st input is op[0],2nd  is op[1] and 3rd input is op[2]

    if len(op)==2:
      element=int(op[1])
    elif len(op)==3:
      index = int(op[1])
      element=int(op[2])


    if op[0]=="insert":
       num.insert(index,element)
       #print(num)
    elif op[0]=="append":
       num.append(element)
       #print(num)
    elif op[0]=="print":
         print(num)
    elif op[0]=="remove":
         num.remove(element)
         #print(num)
    elif op[0]=="reverse":
         num.reverse()
         #print(num)
    elif op[0]=="pop":
         num.pop()
         #print(num)
    elif op[0]=="sort":
         num.sort()
         #print(num)


Input :

12
insert 0 5
insert 1 10
insert 0 6
print
remove 6
append 9
append 1
sort
print
pop
reverse
print
 
Output
 
[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1] 

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment