Advertisement
Nenogzar

Deck of Cards

Feb 19th, 2024 (edited)
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. def add_card(list_card, card_name):
  2.     if card_name not in list_card:
  3.         list_card.append(card_name)
  4.         print("Card successfully added")
  5.     else:
  6.         print("Card is already in the deck")
  7.  
  8.  
  9. def remove_card(list_card, card_name):
  10.     if card_name in list_card:
  11.         list_card.remove(card_name)
  12.         print("Card successfully removed")
  13.     else:
  14.         print("Card not found")
  15.  
  16.  
  17. def remove_index_card(list_card, index):
  18.     if 0 <= index < len(list_card):
  19.         list_card.pop(index)
  20.         print("Card successfully removed")
  21.     else:
  22.         print("Index out of range")
  23.  
  24.  
  25. def insert_card(list_card, index, card_name):
  26.     if abs(index) <= len(list_card):
  27.         if card_name not in list_card:
  28.             list_card.insert(index, card_name)
  29.             print("Card successfully added")
  30.         else:
  31.             print("Card is already added")
  32.     else:
  33.         print("Index out of range")
  34.  
  35.  
  36. cards_list = list(map(str, input().split(", ")))
  37. manipulation_range = int(input())
  38.  
  39. for _ in range(manipulation_range):
  40.     command = list(map(str, input().split(", ")))
  41.  
  42.     manipulation = command[0]
  43.  
  44.     if len(command) == 3:
  45.         card_name = command[2]
  46.         position = int(command[1])
  47.         if manipulation == "Insert":
  48.             insert_card(cards_list, position, card_name)
  49.         else:
  50.             print("Invalid command format")
  51.     elif len(command) == 2:
  52.         if manipulation == "Add":
  53.             add_card(cards_list, command[1])
  54.         elif manipulation == "Remove":
  55.             remove_card(cards_list, command[1])
  56.         elif manipulation == "RemoveAt":
  57.             position = int(command[1])
  58.             remove_index_card(cards_list, position)
  59.  
  60. # print(cards_list)
  61. print(",".join(cards_list))
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement