(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.
print("Enter an amount in double: ")
amount = float(input())
remainingAmount = int(amount * 100)
#Find the number of one dollars
numberOfOneDollars = remainingAmount / 100
remainingAmount = remainingAmount % 100
#Find the number of quarters in the remaining amount
numberOfQuarters = remainingAmount / 25
remainingAmount = remainingAmount % 25
#Find the number of dimes in the remaining amount
numberOfDimes = remainingAmount / 10
remainingAmount = remainingAmount % 10
#Find the number of nickels in the remaining amount
numberOfNickels = remainingAmount / 5
remainingAmount = remainingAmount % 5
#Find the number of pennies in the remaining amount
numberOfPennies = remainingAmount
#Display results
print("Your amount {} consists of".format(amount))
if (numberOfOneDollars == 1):
print(" {} dollar ".format(numberOfOneDollars))
elif (numberOfOneDollars > 1):
print(" {} dollars".format(numberOfOneDollars))
if (numberOfQuarters == 1):
print(" {} quarter ".format(numberOfQuarters))
elif (numberOfQuarters > 1):
print(" {} quarters ".format(numberOfQuarters))
if (numberOfDimes == 1):
print(" {} dime ".format(numberOfDimes))
elif (numberOfDimes > 1):
print(" {} dimes ".format(numberOfDimes))
if (numberOfDimes == 1):
print(" {} nickel ".format(numberOfNickels))
elif (numberOfDimes > 1):
print(" {} nickels".format(numberOfNickels))
if (numberOfPennies == 1):
print(" {} penny".format(numberOfPennies))
elif (numberOfPennies > 1):
print(" {} pennies".format(numberOfPennies))
Output:
Enter an amount in double:
11.5
Your amount 11.5 consists of
11.5 dollars
2.0 quarters