Advertisement
pacho_the_python

deck_of_cards

Oct 22nd, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. cards = input().split(', ')
  2. number = int(input())
  3.  
  4. for i in range(1, number + 1):
  5. command_data = input().split(', ')
  6. command = command_data[0]
  7. if command == 'Add':
  8. card_name = command_data[1]
  9. if card_name not in cards:
  10. cards.append(card_name)
  11. print('Card successfully added')
  12. else:
  13. print('Card is already in the deck')
  14.  
  15. elif command == 'Remove':
  16. card_to_remove = command_data[1]
  17. if card_to_remove in cards:
  18. cards.remove(card_to_remove)
  19. print('Card successfully removed')
  20. else:
  21. print('Card not found')
  22.  
  23. elif command == 'Remove At':
  24. card_idx = int(command_data[1])
  25. if 0 <= card_idx < len(cards):
  26. cards.pop(card_idx)
  27. print('Card successfully removed')
  28. else:
  29. print('Index out of range')
  30.  
  31. elif command == 'Insert':
  32. insert_idx = int(command_data[1])
  33. insert_card_name = command_data[2]
  34.  
  35. if insert_card_name in cards:
  36. print('Card is already added')
  37. elif insert_idx < 0 or insert_idx >= len(cards):
  38. print('Index out of range')
  39. else:
  40. cards.insert(insert_idx, insert_card_name)
  41. print('Card successfully added')
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement