menu
bartleby
search
close search
Hit Return to see all results

E. Returning Multiple Values: You will write a series of functions in a programmake_change_reverse.pyInteger division (floor division operator//) and modulus (mod or remainder operation 96 ) are usefuloperations for working with integersFor example, if you have 39 cents, you can calculate number of quarters as 64//25 2 quarters.Furthermore, the amount left after all quarters are taken out is 64 % 25 14 cents . Likewise, you cancalculate dimes from the amount left as 14//101 dime. The amount left after all dimes are takenout is 14 % 104. The same applies for nickels, after which, the remaining cents is pennies.Another example is getting the ones place of number n by n 9% 10. Then you can get the rest of thenumber with the ones place "deleted" by n//10. Try it. If you continue to do this, you can "pop" off theones place over and over until you have nothing left. This is one way to visit all the digits of a number inreverse order1.Write a function div_mod which takes two parameters a and b and returns two values: adivided by b and a mod b. Note that the division here is integer division, a.ka. floor division (theoperator in Python).Write a function make_change which takes one parameter, the amount of cents, and uses thediv_mod function to calculate number of quarters, dimes, nickels, and pennies in that amount.2.The function returns these four values.Write a function append ones which takes two parameters num and ones and appends theones place ones to the num and returns the result. For example, a call of append_ones (253,7) will return the value 2537Write a function reverse int which uses the functions div_mod and append_ones together toreverse an integer. For example, the call reverse int(1324) would return 42313.4.5.Now write the main function. Ask the user to enter an amount of cents and calculate thechange (quarters, dimes, nickes, and pennies) for the amount and for that amount reversed6.Don't forget to call the main function in your script.Test your program on at least two values.Shoot a screenshot of your Python Shell showing your two interactions and paste it here

Question

How do repeat the cents value? For example if I use the argument cents(1234), it should print 4321 (backwards as you can see) but I can't see to do that with my code. Thanks 

E. Returning Multiple Values: You will write a series of functions in a program
make_change_reverse.py
Integer division (floor division operator//) and modulus (mod or remainder operation 96 ) are useful
operations for working with integers
For example, if you have 39 cents, you can calculate number of quarters as 64//25 2 quarters.
Furthermore, the amount left after all quarters are taken out is 64 % 25 14 cents . Likewise, you can
calculate dimes from the amount left as 14//101 dime. The amount left after all dimes are taken
out is 14 % 104. The same applies for nickels, after which, the remaining cents is pennies.
Another example is getting the ones place of number n by n 9% 10. Then you can get the rest of the
number with the ones place "deleted" by n//10. Try it. If you continue to do this, you can "pop" off the
ones place over and over until you have nothing left. This is one way to visit all the digits of a number in
reverse order
1.
Write a function div_mod which takes two parameters a and b and returns two values: a
divided by b and a mod b. Note that the division here is integer division, a.ka. floor division (the
operator in Python).
Write a function make_change which takes one parameter, the amount of cents, and uses the
div_mod function to calculate number of quarters, dimes, nickels, and pennies in that amount.
2.
The function returns these four values.
Write a function append ones which takes two parameters num and ones and appends the
ones place ones to the num and returns the result. For example, a call of append_ones (253,
7) will return the value 2537
Write a function reverse int which uses the functions div_mod and append_ones together to
reverse an integer. For example, the call reverse int(1324) would return 4231
3.
4.
5.
Now write the main function. Ask the user to enter an amount of cents and calculate the
change (quarters, dimes, nickes, and pennies) for the amount and for that amount reversed
6.
Don't forget to call the main function in your script.
Test your program on at least two values.
Shoot a screenshot of your Python Shell showing your two interactions and paste it here
help_outline

Image Transcriptionclose

E. Returning Multiple Values: You will write a series of functions in a program make_change_reverse.py Integer division (floor division operator//) and modulus (mod or remainder operation 96 ) are useful operations for working with integers For example, if you have 39 cents, you can calculate number of quarters as 64//25 2 quarters. Furthermore, the amount left after all quarters are taken out is 64 % 25 14 cents . Likewise, you can calculate dimes from the amount left as 14//101 dime. The amount left after all dimes are taken out is 14 % 104. The same applies for nickels, after which, the remaining cents is pennies. Another example is getting the ones place of number n by n 9% 10. Then you can get the rest of the number with the ones place "deleted" by n//10. Try it. If you continue to do this, you can "pop" off the ones place over and over until you have nothing left. This is one way to visit all the digits of a number in reverse order 1. Write a function div_mod which takes two parameters a and b and returns two values: a divided by b and a mod b. Note that the division here is integer division, a.ka. floor division (the operator in Python). Write a function make_change which takes one parameter, the amount of cents, and uses the div_mod function to calculate number of quarters, dimes, nickels, and pennies in that amount. 2. The function returns these four values. Write a function append ones which takes two parameters num and ones and appends the ones place ones to the num and returns the result. For example, a call of append_ones (253, 7) will return the value 2537 Write a function reverse int which uses the functions div_mod and append_ones together to reverse an integer. For example, the call reverse int(1324) would return 4231 3. 4. 5. Now write the main function. Ask the user to enter an amount of cents and calculate the change (quarters, dimes, nickes, and pennies) for the amount and for that amount reversed 6. Don't forget to call the main function in your script. Test your program on at least two values. Shoot a screenshot of your Python Shell showing your two interactions and paste it here

fullscreen
check_circleAnswer
Step 1

Program Instructions:

  • In the function reverse_int(), take a string variable word, and use it to append the results of a%b one by one backwards.
  • In the function append_ones(), convert the arguments to string and append them to return the result.
  • The function div_mod calculates division and mod of the variables a and b, and use the function in make_change to convert cents.
Step 2

Program:

def div_mod(a,b):

   d = a // b

   r = a % b

   return (d,r)

def make_change(cents):

  quarter, remain_cents = div_mod(cents, 25)

  dimes, remain_cents = div_mod(cents, 10)

  nickles, remain_cents = div_mod(cents, 5)

  pennis = remain_cents

  return (quarter,dimes,nickles,pennis)

def append_ones(num,ones):

  n = str(num)+str(ones)

  return n

def reverse_int(num):

  word = ""

  reverse_num = num

  while reverse_n...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: 11,12,13

A: Two main advantages of storing data digitally rather than in analog format are:Data stored in digita...

question_answer

Q: Write a program called LoopMinMax that reads in 4 values from the user and prints the lowest and hig...

A: You didn’t mention which language should be used for the given program. Here, I have used JAVA langu...

question_answer

Q: Programming in C

A: Note: The given C program has been compiled and executed in "repl.it" online complier.

question_answer

Q: getRandomLib.h: // This library provides a few helpful functions to return random values// * getRand...

A: Program Instructions:Include the necessary header files.Print hello message and as for a response.De...

question_answer

Q: Write two cin statements to get input values into birthMonth and birthYear. Then write a statement t...

A: Explanation:A C++ program should include header file “<iostream>”, begins with “#” sign.This h...

question_answer

Q: create a file in c++. In this lab, you will replace the existing functions with more flexible ones, ...

A: Program Instructions:Define the necessary constants and header files.Use displayMessage() function t...

question_answer

Q: What does the group nesting depend on?

A: Group Nesting:A group can have any number of contacts, users, or other groups as members. And the ne...

question_answer

Q: A Maze Room : In this lab, we will make a maze game. The maze is based on Linked Lists. Instead of h...

A: For class Room, implement the setter and getter methods by assign and returning values respectively....

question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz =2; y = z + x;...

A: Call by reference The arguments passed to a function will copy the address of an argument into the f...

Sorry about that. What wasn’t helpful?