Write a function piggyBank that accepts a sequence of "coins" and returns counts of the coins and the total value of the bank. ⚫ the coins will be given by a list of single characters, each one of 'Q', 'D', 'N',P', representing quarter, dime, nickel, penny ⚫ the function returns a tuple with two items: 1. a dictionary with counts of each denomination. They should always be listed in the order 'Q', 'D', 'N',P' 2. the total value in whole cents of the amount in the bank Sample usage: 1 >>> piggyBank(['D', 'P', 'Q', 'Q', 'D', 'P', 'P']). 2 ({'Q' 2, 'D': 2, 'N': 0, 'P': 3}, 73) 3 >>> piggyBank (['D', 'D', 'N', 'N', 'N']) 4 5 6 7 ({'Q': 0, 'D': 2, 'N': 3, 'P': 0}, 35) >>> piggyBank (['P', 'D', 'N', 'P', 'N', 'N', 'N', 'Q', 'D', 'P', 'Q', 'Q', 'D']) ({'Q' 3, 'D': 3, 'N': 4, 'P': 3}, 128) >>> piggyBank (['D', 'P', 'Q', 'Q', 'D', 'P', 'P'])==({'Q': 2, 'D': 2, 'N': 0, 'P': 3}, 73) 8 True
Write a function piggyBank that accepts a sequence of "coins" and returns counts of the coins and the total value of the bank. ⚫ the coins will be given by a list of single characters, each one of 'Q', 'D', 'N',P', representing quarter, dime, nickel, penny ⚫ the function returns a tuple with two items: 1. a dictionary with counts of each denomination. They should always be listed in the order 'Q', 'D', 'N',P' 2. the total value in whole cents of the amount in the bank Sample usage: 1 >>> piggyBank(['D', 'P', 'Q', 'Q', 'D', 'P', 'P']). 2 ({'Q' 2, 'D': 2, 'N': 0, 'P': 3}, 73) 3 >>> piggyBank (['D', 'D', 'N', 'N', 'N']) 4 5 6 7 ({'Q': 0, 'D': 2, 'N': 3, 'P': 0}, 35) >>> piggyBank (['P', 'D', 'N', 'P', 'N', 'N', 'N', 'Q', 'D', 'P', 'Q', 'Q', 'D']) ({'Q' 3, 'D': 3, 'N': 4, 'P': 3}, 128) >>> piggyBank (['D', 'P', 'Q', 'Q', 'D', 'P', 'P'])==({'Q': 2, 'D': 2, 'N': 0, 'P': 3}, 73) 8 True
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images