Advertisement
akosiraff

Download CoinValue & Unzip Answer

Oct 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1.  
  2. Download: https://solutionzip.com/downloads/coinvalue-unzip/
  3. Q1. Write a Python program that repeatedly asks the user to input coin values (1 or 5 or
  4. 10 or 25) until the total amount matches a target value. The target value is a randomly
  5. generated integer between 1 and 99 inclusively. For example, for a target value of 31,
  6. coin values entered by the user should be 25, 5, and 1 because 31 = 25 + 5 +
  7. 1.
  8. When a game session starts, the player is asked to enter a valid coin value (1 or 5 or
  9. 10 o 25). If the player enters a coin value that is not valid (i.e. the coin value is not 1 or
  10. 5 or 10 or 25) the program prompts the player to enter a valid value. The program
  11. continues to prompt the player to enter a valid value until the player enters a valid
  12. value. If the player presses key without entering a value the game session
  13. ends and the outcome of the game is reported.
  14. A game session in the game ends with success or failure. The player attempt is
  15. successful if the player is able to enter valid coin values that add up to the total coin
  16. value. The player attempt fails if the player enters coin values that add up to more
  17. than or less than the total coin value.
  18. In event of failure an appropriate message indicates by how many cents did the player
  19. exceeded the target amount or by how many cents was the player short of the target
  20. amount. Once the outcome (success or failure) has been reported the player is
  21. prompted to enter the letter ‘y’ or the letter ‘n’ to indicate whether they wish to play
  22. another game session. If the player enters ‘y’ a new game session with a new random
  23. coin value is started. If the player enters any value other than ‘y’ the program ends.
  24. Q2. A tuple is sequence of comma separated values inside parenthesis. For instance (2,3) is a two-tuple. Write a function called unzip that takes in a list of two-tuples in its parameters and returns a tuple of two lists.
  25. call to unzip([(1,4),(2,5),(3,6)]) would return ([1,2,3],[4,5,6]) . a call to unzip([(1,2)]) would return ([1],[2])
  26. a call to unzip([(‘A’,’B’),(‘X’,’Y’)]) would return ([‘A’,’X’],[‘B’,’Y’]) a call to unzip([]) would return ([],[])
  27. Test your function by calling the function from inside the main function.
  28.  
  29. Download: https://solutionzip.com/downloads/coinvalue-unzip/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement