sibinasto

CARDS

Apr 6th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. def add(my_list, card):
  2.     if card in my_list:
  3.         print("Card is already in the deck")
  4.     else:
  5.         my_list.append(card)
  6.         print("Card successfully added")
  7.     return my_list
  8.  
  9.  
  10. def remove(my_list, card):
  11.     if card in my_list:
  12.         print("Card successfully removed")
  13.         my_list.remove(card)
  14.     else:
  15.         print("Card not found")
  16.     return my_list
  17.  
  18.  
  19. def remove_at(my_list, i):
  20.     if 0 <= i < len(my_list):
  21.         my_list.pop(i)
  22.         print("Card successfully removed")
  23.     else:
  24.         print("Index out of range")
  25.     return my_list
  26.  
  27.  
  28. def insert(my_list, i, card):
  29.     if 0 <= i < len(my_list):
  30.         if card in my_list:
  31.             print("Card is already added")
  32.         else:
  33.             print("Card successfully added")
  34.             my_list.insert(i, card)
  35.     else:
  36.         print("Index out of range")
  37.     return my_list
  38.  
  39.  
  40. owned_cards = input().split(", ")
  41. n_commands = int(input())
  42.  
  43. for _ in range(n_commands):
  44.     command = input().split(", ")
  45.     action = command[0]
  46.  
  47.     if action == "Add":
  48.         card = command[1]
  49.         owned_cards = add(owned_cards, card)
  50.     elif action == "Remove":
  51.         card = command[1]
  52.         owned_cards = remove(owned_cards, card)
  53.     elif action == "Remove At":
  54.         index = int(command[1])
  55.         owned_cards = remove_at(owned_cards, index)
  56.     elif action == "Insert":
  57.         index = int(command[1])
  58.         card = command[2]
  59.         owned_cards = insert(owned_cards, index, card)
  60.  
  61. print(", ".join(owned_cards))
Advertisement
Add Comment
Please, Sign In to add comment