Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/2 November 2019/1. - Wizard Poker

Nov 5th, 2019
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 2 November 2019 Group 1
  3. Check your code: https://judge.softuni.bg/Contests/1859/Programming-Fundamentals-Mid-Exam-2-November-2019-Group-1
  4.  
  5. SUPyF2 P.-Mid-Exam/2 November 2019/1. - Wizard Poker
  6.  
  7. Problem:
  8. The world is threatened by an enemy never seen before. Your hero's weapon seems to be useless against the enemy.
  9. But your hero has a super strong arsenal full of powerful magic cards and will challenge the enemy to a card duel
  10. to the death and he needs your help to create a deck.
  11. Create a program that adds, inserts, removes and swaps cards in a new deck.
  12. On the first line, you will receive all cards in the form of strings separated by ":".
  13.  
  14. Until you receive the "Ready" command, you will get commands in the format:
  15. • Add {card name}
  16. • Adds the card to the end of the deck.
  17. • If the card doesn't exist in print "Card not found."
  18. • Insert {card name} {index}
  19. • Insert the card at the given index of the deck.
  20. • If the card doesn't exist or the index is invalid print "Error!"
  21. • Remove {card name}
  22. • Remove the card from the deck.
  23. • If the card doesn't exist in print "Card not found."
  24. • Swap {card name 1} {card name 2}
  25. • Swap the positions of the cards.
  26. • Input will always be valid
  27. • Shuffle deck
  28. • Reverse the deck
  29. When you receive the "Ready" command print the cards in the deck separated by space.
  30.  
  31. Input:
  32. • On the 1st line, you will receive the arsenal of all cards available separated by ":".
  33. • On the next lines, until you receive the "Ready" command you will receive commands to arrange your deck.
  34.  
  35. Output:
  36. • Print the cards in your deck on a single line, separated by a single space.
  37.  
  38. Examples:
  39.  
  40. Input:                                          Output:
  41. Innervate:Moonfire:Pounce:Claw:Wrath:Bite       Wrath Pounce Claw Moonfire
  42. Add Moonfire
  43. Add Pounce
  44. Add Bite
  45. Add Wrath
  46. Insert Claw 0
  47. Swap Claw Moonfire
  48. Remove Bite
  49. Shuffle deck
  50. Ready
  51.  
  52. Comments:
  53. First command is Add Moofire and now our deck has one card in it.
  54. 1. Moonfire Pounce
  55. 2. Moonfire Pounce Bite
  56. 3. Moonfire Pounce Bite Wrath
  57. 4. Claw Moonfire Pounce Bite Wrath
  58. 5. Moonfire Claw Pounce Bite Wrath
  59. 6. Moonfire Claw Pounce Wrath
  60. 7. Wrath Pounce Claw Moonfire
  61.  
  62. Input:
  63. Wrath:Pounce:Lifeweaver:Exodia:Aso:Pop
  64. Add Pop
  65. Add Exodia
  66. Add Aso
  67. Remove Wrath
  68. Add SineokBqlDrakon
  69. Shuffle deck
  70. Insert Pesho 0
  71. Ready
  72.  
  73. Output:
  74. Card not found.
  75. Card not found.
  76. Error!
  77. Aso Exodia Pop
  78. """
  79. cards = input().split(":")
  80. new_cards = []
  81.  
  82. while True:
  83.     command = input().split()
  84.     if command[0] == "Ready":
  85.         print(*new_cards)
  86.         break
  87.  
  88.     elif command[0] == "Add":
  89.         add_card_name = command[1]
  90.         if add_card_name in cards:
  91.             new_cards.append(add_card_name)
  92.         else:
  93.             print(f"Card not found.")
  94.  
  95.     elif command[0] == "Insert":
  96.         insert_card_name = command[1]
  97.         insert_index = int(command[2])
  98.         if insert_card_name in cards and 0 <= insert_index < len(new_cards):
  99.             new_cards.insert(insert_index, insert_card_name)
  100.         else:
  101.             print("Error!")
  102.  
  103.     elif command[0] == "Remove":
  104.         remove_card_name = command[1]
  105.         if remove_card_name in new_cards:
  106.             new_cards.remove(remove_card_name)
  107.         else:
  108.             print(f"Card not found.")
  109.  
  110.     elif command[0] == "Swap":
  111.         swap_card_1 = command[1]
  112.         swap_card_2 = command[2]
  113.         index_swap_card_1 = new_cards.index(swap_card_1)
  114.         index_swap_card_2 = new_cards.index(swap_card_2)
  115.         new_cards.remove(swap_card_1)
  116.         new_cards.remove(swap_card_2)
  117.         new_cards.insert(index_swap_card_1, swap_card_2)
  118.         new_cards.insert(index_swap_card_2, swap_card_1)
  119.  
  120.     elif command[0] == "Shuffle":
  121.         new_cards = reversed(new_cards)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement