116k views
5 votes
(Financial application: monetary units) Modify Listing 3.4, ComputeChange.py, to display the nonzero denominations only, using singular words for single units such as 1 dollar and 1 penny, and plural words for more than one unit such as 2 dollars and 3 pennies.

User First
by
5.0k points

1 Answer

5 votes

Answer:

The Python code is given below

Step-by-step explanation:

changeNonZeroDenominations.py

amount = eval(input("Enter an amount, for example, 11.56: "))

remainingAmount = int(amount * 100)

numberOfOneDollars = remainingAmount // 100

remainingAmount = remainingAmount % 100

numberOfQuaters = remainingAmount // 25

remainingAmount = remainingAmount % 25

numberOfDimes = remainingAmount // 100

remainingAmount = remainingAmount % 100

numberOfNickels = remainingAmount // 5

remainingAmount = remainingAmount % 56

numberOfPennies = remainingAmount

print("Your amount", amount , "consists of\\")

if numberOfOneDollars != 0:print("\t", numberOfOneDollars, "dollars")

if numberOfQuaters !=0 :print("\t", numberOfQuaters, "quaters")

if numberOfDimes:print("\t", numberOfDimes, "dimes")

if numberOfNickels != 0:print("\t", numberOfNickels, "nickels")

if numberOfPennies != 0:print("\t", numberOfPennies, "pennies")

User Alexandre Thenorio
by
5.3k points