Problem #1: Warm-up exercise
Design and write a custom function named CountCoins that meets these specifications:
Accepts a string as an input argument. Each character in the string represents a coin. The allowed
characters and their equivalent monetary values are: 'Q' for quarter ($0.25), 'D' for dime ($0.10), 'N'
for nickel ($0.05), and 'P' for penny ($0.01). Note that lowercase versions are also acceptable.
Uses a for loop to access the string's characters to count the number of quarters, dimes, nickels, and
pennies present in the string. Ignore any character that is not one of the listed coins.
Returns these two output values:
Ο A tuple that contains the number of each coin type in the string (in the order Q, D, N, P)
The total monetary value of the coins (in U.S. dollars $)
Ο
Example 1: If the input string is 'PN', there are 0 quarters, 0 dimes, 1 nickel, and 1 penny. The function
should return the count tuple (0, 0, 1, 1) and the money value 0.06.
Example 2: If the input string is 'DQQPNDPP', there are 2 quarters, 2 dimes, 1 nickel, and 3 pennies. The
function should return the count tuple (2, 2, 1, 3) and the money value 0.78.
In the main section of the Python script, test your function. These are the requirements:
Within a while loop:
Ο
Ο
Ο
Ο
Prompts the user to enter a string containing the desired coin characters.
If the first character of the string is an 'X' or 'x', then the program should quit.
Invokes your CountCoins function.
Pass it the appropriate input argument and store the output values that it returns.
Displays the count tuple.
Displays the returned money value to two (2) decimal places.
► Save the script using this file name: L2_p1.py
Sample Runs
Enter the coin string: qqqqppnndd
Coin count (Q,D,N,P) = (4, 2, 2, 2)
Monetary value = $1.32
Enter the coin string: NnDq
Coin count (Q,D,N,P) = (1, 1, 2, 0)
Monetary value = $0.45
Enter the coin string: x