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

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================
amount = float(input('Enter amount: '))

# convert amount to all pennies by x 100
amount = amount * 100

# number of dollar than fit in that amount is amount / 100
dollars = amount // 100  # doing integer division dont need the fraction part
pennies_left = amount - dollars * 100

# number of quarter than fit is pennies_left//25
quarters = pennies_left // 25
pennies_left = pennies_left - quarters * 25

# number of dimes that can fit is dimes//10
dimes = pennies_left // 10
pennies_left = pennies_left - dimes * 10

# number of nickels that can fit pennies_left//5
nickels = pennies_left // 5
pennies_left = pennies_left - nickels * 5

print('Exchange:')
print('{} X $1 bill'.format(round(dollars)))
print('{} X quarters'.format(round(quarters)))
print('{} X dimes'.format(round(dimes)))
print('{} X nickels'.format(round(nickels)))
print('{} X pennies'.format(round(pennies_left)))


Related Solutions

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...
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...
1. Write a function named computeInterest that computes the amount # of interest on a given...
1. Write a function named computeInterest that computes the amount # of interest on a given amount of money. The function should accept # the amount of starting money (deposit) and the interest rate (rate) # and return total amount of money in account after the interest is added. # Just use a basic interest calculations. For example, for a deposit of # 100 and a rate of 0.045 your function should return 104.5. # You must have exception handling....
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....
Write a C++ code for these 2 questions 1. Create an integer variable named ‘arraySize’ and...
Write a C++ code for these 2 questions 1. Create an integer variable named ‘arraySize’ and initialize the value to 1000. 2.. Open an output file named ‘GroupAssignment2Results.csv’. The first line of this file should be the column headings: ‘Array Size’, ‘Bubble Sort Time’, ‘Selection Sort Time’, ’Insertion Sort Time’, ‘Quick Sort Time’, ‘Merge Sort Time’.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT