This problem will get you acquainted with how to format a floating point number to a fixed number of decimal places. In this case, the number of decimal places will be 2 for representing dollars and cents.
You will write a program that asks the user for a number of quarters, dimes, nickels, and pennies. Perhaps these coins are in their pocket. After obtaining those values, your program should compute and output the total number of dollars and cents.
To nicely format a floating point variable as a dollars and cents we will use:
formatted_str = "${:.2f}".format(amount)
The Python statement above converts the floating point value in the variable amount to a string and assigns it to a variable named formatted_str. The number 2 in the statement sets the precision. You should play with the statement first in the IDLE shell window using different values for the precision and amount to see how the statement works. You ca place any text outside of the curly brackets. In this case, we are using a "$" to represent money.
Below is a sample run of the completed program.
Pocket change calculator
How many quarters?6
How many dimes?7
How many nickels?5
How many pennies?5
You have $2.50