Question

In: Computer Science

Write code that classifies a given amount of money (which you store in a variable named...

Write code that classifies a given amount of money (which you store in a variable named amount), specified in cents, as greater monetary units. Your code lists the monetary equivalent in dollars (100 ct), quarters (25 ct), dimes (10 ct), nickels (5 ct), and pennies (1 ct). Your program should report the maximum number of dollars that fit in the amount, then the maximum number of quarters that fit in the remainder after you subtract the dollars, then the maximum number of dimes that fit in the remainder after you subtract the dollars and quarters, and so on for nickels and pennies. The result is that you express the amount as the minimum number of coins needed.

Please show me how to do it in the jupyter notebook.

Solutions

Expert Solution

money = int(input("enter total amount of money you have:\t"))

count_dollars = 0
count_quarters = 0
count_dimes = 0
count_nickels = 0
count_pennies = 0
dollar = 100
quarter = 25
dime = 10
nickel = 5
pennie = 1
while(money > 0):
    if(money > dollar):
        money = money - dollar
        count_dollars += 1
    elif(money > quarter):
        money = money - quarter
        count_quarters += 1
    elif(money > dime):
        money = money - dime
        count_dimes += 1
    elif(money > nickel):
        money = money - nickel
        count_nickels += 1
    elif(money > pennie):
        money = money - pennie
        count_pennies += 1
    else:
        break
print("{} dollars, {} quarters, {} dimes, {} nickels, {} pennies".format(count_dollars, count_quarters, count_dimes, count_nickels, count_pennies))
  


If you have any doubts please comment and please don't dislike.


Related Solutions

Write a class named GasTank containing: An instance variable named amount of type double, initialized to...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is...
Given two String arrays (named below), write the code that you would need in order to...
Given two String arrays (named below), write the code that you would need in order to copy the data from relatives into weddingInvitations in java. 1. relatives (which is loaded with data) 2. weddingInvitations (that is the same size as relatives)
Write the code to create an array named movies and store three of your favorite movies...
Write the code to create an array named movies and store three of your favorite movies in the array. Only provide the array and code needed to put the movie names in the array. Do not include additional code
Which of the following statement is incorrect? a. A given amount of money you must pay...
Which of the following statement is incorrect? a. A given amount of money you must pay out today is a greater burden than the same amount paid in the future. b. Most of the answers are correct. c. With an amortized loan, the amount of interest increases each year, and the amount contributed to principal decreases each year. d. With an amortized loan, the amount of interest decreases each year, and the amount contributed to principal increases each year. e....
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money...
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money from 0 to 99 cents. The program then calculates and displays the number of coins from each denomination: quarters (25 cents), dimes (10 cents), nickels (5 cents), and cents. For example, if the user enters 93, your program should display There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents Note: You must use integer division and modular division to...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.  
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.
Given a String variable named sentence that has been initialized, write an expression whose value is...
Given a String variable named sentence that has been initialized, write an expression whose value is the the very last character in the String referred to by sentence. write it in python
Part I: Prompt the user for a single string and store it in a variable named...
Part I: Prompt the user for a single string and store it in a variable named userString. a. Use a for loop to print the string, char by char, with a dash '-' char between each. b. Use a for loop to print the string backwards, char by char, with a dash '-' char between each. Part II: Create an array of 5 strings named userStrings. Use a generalized array size. const int n = 5; string userStrings[n]; a. Populate...
The manager of a home improvement store wishes to estimate the mean amount of money spent in the store.
The manager of a home improvement store wishes to estimate the mean amount of money spent in the store. The estimate is to be within $4.00 with a 95% level of confidence. The manager does not know the standard deviation of the amounts spent. However, he does estimate that the range is from $5.00 up to $155.00. How large of a sample is needed?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT