Advertisement
yordan_yordanov

Deck of Cards

Nov 7th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. cards_owned = input().split(", ")
  2. n = int(input())
  3.  
  4. for i in range(n):
  5. command = input().split(", ")
  6.  
  7. if command[0] == "Add":
  8. name = command[1]
  9. if name in cards_owned:
  10. print(f"Card is already bought")
  11. else:
  12. print(f"Card successfully bought")
  13. cards_owned.append(name)
  14.  
  15. if command[0] == "Remove":
  16. name = command[1]
  17. if name in cards_owned:
  18. print("Card successfully sold")
  19. cards_owned.remove(name)
  20. else:
  21. print("Card not found")
  22.  
  23. if command[0] == "Remove At":
  24. if int(command[1]) < len(cards_owned):
  25. del cards_owned[int(command[1])]
  26. print("Card successfully sold")
  27. else:
  28. print("Index out of range")
  29.  
  30. if command[0] == "Insert":
  31. name = command[2]
  32. if int(command[1]) >= len(cards_owned):
  33. print("Index out of range")
  34. else:
  35. if command[2] not in cards_owned:
  36. cards_owned.insert(int(command[1]), name)
  37. print("Card successfully bought")
  38. else:
  39. print("Card is already bought")
  40.  
  41. result_string = ", ".join(cards_owned)
  42. print(result_string)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement