Advertisement
koteshkoeziche

Deck of Cards

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