1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tekilochka [14]
3 years ago
13

Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin

type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.

Computers and Technology
1 answer:
Serjik [45]3 years ago
3 0

Answer:

Here is the Python program:

def FewestCoinVals():  # function to output change using fewest coins

 total_change = int(input('Enter change amount in pennies: '))

#prompts user to enter total change amount in pennies

 if total_change <= 0:  # if value of total_change is less or equal to 0

   print('no change')  # prints no change

 else:  # if value of total_change is greater than 0

   dollars = total_change // 100  

#calculate value of dollars by dividing total_change by 100

   total_change %= 100   #take mod of value of total_change with 100

#calculate value of quarters by dividing total_change by 100

   quarters = total_change // 25

   total_change %= 25  #take mod of value of total_change with 25

#calculate value of dimes by dividing total_change by 100

   dimes = total_change // 10  

   total_change %= 10  #take mod of value of total_change with 10

#calculate value of nickels by dividing total_change by 100

   nickels = total_change // 5

   total_change %= 5  #take mod of value of total_change with 5

   pennies = total_change  

#value of pennies is equal to value of total_change

#the if elif statement checks for the singular and plural coin names

   if dollars >1:

       print('dollars: ',dollars)

   elif dollars ==1:

       print('dollar: ',dollars)

   if quarters > 1:

       print('quarters: ',quarters)

   elif quarters ==1:

       print('quarter: ',quarters)

   if dimes >1:

       print('dimes: ',dimes)

   elif dimes ==1:

       print('dime: ',dimes)

   if nickels >1:

       print('nickels: ',nickels)

   elif nickels ==1:

       print('nickel: ',nickels)

   if pennies >1:

       print('pennies: ',pennies)

   elif pennies ==1:

       print('penny: ',pennies)

#calls the FewestCoinVals() function        

FewestCoinVals()

                     

Explanation:

The program prompts the user to enter change amount in pennies and has int() function to convert input value to integer.  If the value entered is less than or equal to 0 it displays message "no change", otherwise it converts the value using fewest coins. The formulas for converting to each type is given in the code. It uses if and elif statements to check if the final value of total_change has singular or plural coin names such as penny or pennies. The program along with output is attached as the screen shot.

You might be interested in
FOR PYTHON 3
VLD [36.1K]

Answer:

Complete Python code with step by step comments for explanation are given below.

Python Code:

# creating a function named scrabble_number that will take num as input argument

def scrabble_number(num):

   # print the original number  

   print("The original number is: ",num)  

   # we can implement the required logic by using python built-in functions join() and zip()  

   scrambled = ''.join([char[1]+char[0] for char in zip(num[::2], num[1::2])])  

   # print the scrambled number

   print("The scrambled number is: " + str(scrambled))  

Driver code:

scrabble_number('123456')

Output:

The original number is: 123456

The scrambled number is: 214365

5 0
3 years ago
A client is currently struggling with late-stage integration and manual deployments. They want to find another method that will
Papessa [141]

Answer:

It can deliver the services faster with higher reliability and quality

4 0
3 years ago
To enter new code that performs as intended in the place of the old code that produces an error is the goal of
Tanzania [10]

Answer:

Fixing code in a software program.

Explanation:

It is regarded the easiest application development method, that is in many cases the standard (method)

Fixing code well into the software program because they came to realize that there was some error while they compose the program, then he will modify the program and then they will fix that again.

5 0
3 years ago
What is the outlined area called?
LenKa [72]

Answer:

If you're talking about perimeter (the length of the outer edges)

Explanation:

6 0
4 years ago
The transmission control protocol (TCP) and internet protocol (IP) are used in Internet communication. Which of the following be
SpyIntel [72]

Answer:

To establish a common standard for sending messages between devices on the Internet, C

Explanation:

5 0
3 years ago
Other questions:
  • Database management systems _____. a. include transaction-processing reports for database analysis b. are used to create, organi
    6·1 answer
  • Write a literal representing the false value in c++.
    11·1 answer
  • Do you watch markiplier?
    13·2 answers
  • QuickBooks Online (QBCU) Session 4: Post Assessme
    12·1 answer
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • What symbol is used for an assignment statement in a flowchart?
    8·1 answer
  • What is an Operating system??
    5·1 answer
  • Write a program that will make a copy of a text file, line by line. Read the name of the existing file and name of the new file(
    13·1 answer
  • "a web client that connects to a web server, which is in turn connected to a bi application server, is reflective of a"
    7·1 answer
  • Which of the following is not a valid Java identifier? a. Factorial, b. anExtremelyLongldentifierlfYouAskMe, c. 2ndLevel, d. Iev
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!