Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: https://solutionzip.com/downloads/coinvalue-unzip/
- Q1. Write a Python program that repeatedly asks the user to input coin values (1 or 5 or
- 10 or 25) until the total amount matches a target value. The target value is a randomly
- generated integer between 1 and 99 inclusively. For example, for a target value of 31,
- coin values entered by the user should be 25, 5, and 1 because 31 = 25 + 5 +
- 1.
- When a game session starts, the player is asked to enter a valid coin value (1 or 5 or
- 10 o 25). If the player enters a coin value that is not valid (i.e. the coin value is not 1 or
- 5 or 10 or 25) the program prompts the player to enter a valid value. The program
- continues to prompt the player to enter a valid value until the player enters a valid
- value. If the player presses key without entering a value the game session
- ends and the outcome of the game is reported.
- A game session in the game ends with success or failure. The player attempt is
- successful if the player is able to enter valid coin values that add up to the total coin
- value. The player attempt fails if the player enters coin values that add up to more
- than or less than the total coin value.
- In event of failure an appropriate message indicates by how many cents did the player
- exceeded the target amount or by how many cents was the player short of the target
- amount. Once the outcome (success or failure) has been reported the player is
- prompted to enter the letter ‘y’ or the letter ‘n’ to indicate whether they wish to play
- another game session. If the player enters ‘y’ a new game session with a new random
- coin value is started. If the player enters any value other than ‘y’ the program ends.
- 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.
- 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])
- a call to unzip([(‘A’,’B’),(‘X’,’Y’)]) would return ([‘A’,’X’],[‘B’,’Y’]) a call to unzip([]) would return ([],[])
- Test your function by calling the function from inside the main function.
- Download: https://solutionzip.com/downloads/coinvalue-unzip/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement