Write a program that asks the user for an integer between 0 and 100 that represents a number of cents. Convert that number of cents to the equivalent number of quarters, dimes, nickels, and pennies. Then output the maximum number of quarters that will fit the amount, then the maximum number of dimes that will fit into what then remains, and so on. If the amount entered is negative, write an error message and quit. Amounts greater than 100 are OK (the user will get many quarters.) Use extended assembly instructions and exception handler services. Enter number of cents: 67 Number of quarters:2 Number of dimes :1 Number of nickels :1 Number of pennies :2

Respuesta :

Solution :

import [tex]$\text{math}$[/tex]

#First we need to define the value of each coin

[tex]$\text{penny=1}$[/tex]

[tex]$\text{nickel}$[/tex] = 5

[tex]$\text{dime}$[/tex] = 10

[tex]$\text{quarter}$[/tex] = 25

#Here we define [tex]$\text{the variables}$[/tex] to hold the [tex]$\text{max}$[/tex] number of each coin

[tex]$\text{quarter}$[/tex]s = 0

[tex]$\text{dime}$[/tex]s = 0

[tex]$\text{nickel}$[/tex]s = 0

[tex]$\text{pennys}$[/tex] = 0

[tex]$\text{cents}$[/tex] = int([tex]$\text{inpu}t $[/tex]("Please enter an [tex]$\text{amount}$[/tex] of money you have in [tex]$\text{cents}$[/tex]: "))

if [tex]$\text{cents}$[/tex] [tex]${data-answer}gt;0$[/tex] and [tex]$\text{cents}$[/tex] [tex]${data-answer}lt;=$[/tex] 100:

   if [tex]$\text{cents}$[/tex] >= 25:

       quarters = [tex]$\text{cents}$[/tex] / quarter

       [tex]$\text{cents}$[/tex] = [tex]$\text{cents}$[/tex] % quarter

   if [tex]$\text{cents}$[/tex] >= 10:

       dimes = cents/dime

       [tex]$\text{cents}$[/tex] =[tex]$\text{cents}$[/tex] % dime

   if [tex]$\text{cents}$[/tex] >= 5:

       nickels =[tex]$\text{cents}$[/tex] /nickel

       [tex]$\text{cents}$[/tex] = [tex]$\text{cents}$[/tex] % nickel

   if [tex]$\text{cents}$[/tex] > 0:

       pennys = [tex]$\text{cents}$[/tex] / penny

       [tex]$\text{cents}$[/tex] = 0

    print("The coins are: "

       "\[tex]$\text{nQuarters}$[/tex]", math.floor(quarters),

       "\[tex]$\text{nDimes}$[/tex]", math[tex]$\text{.floor}$[/tex](dimes), "\[tex]$\text{nNickels}$[/tex]", math[tex]$\text{.floor}$[/tex](nickels), "\nPennies", math[tex]$\text{.floor}$[/tex](pennys))

else:

   print("wrong value")