Write a Python program (called q2.py) that for a given change amount, reports th
ID: 3742430 • Letter: W
Question
Write a Python program (called q2.py) that for a given change amount, reports the
maximum number of dollars followed by the number of quarters, dimes, nickels, and
pennies. Hint: You might find it easier to convert the change amount to cents and
then proceeding with your calculations.
Example #1.
Enter the change amount : 11.42
11 d o l l a r s
1 q u a r t e r s
1 dimes
1 n i c k e l s
2 pennies
Example #2.
Enter the change amount : 4.32
4 d o l l a r s
1 q u a r t e r s
0 dimes
1 n i c k e l s
2 pennies
Explanation / Answer
def main(): change = float(input('Enter the change amount : ')) dollars = int(change) change = (change * 100) % 100 pennies = change quarters = pennies // 25 pennies %= 25 dimes = pennies // 10 pennies %= 10 nickels = pennies // 5 pennies %= 5 print(dollars, 'dollars') print(int(quarters), 'quarters') print(int(dimes), 'dimes') print(int(nickels), 'nickels') print(int(pennies), 'pennies') main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.