Question

In: Computer Science

Create a program/function using PYTHON that takes cents and returns to the customer how MANY coins...

Create a program/function using PYTHON that takes cents and returns to the customer how MANY coins it takes to make the change...

Ex. if the change owed is 50 cents then return a 2 (for two quarters)

if the change owed is 10 cents then return a 1 (for one dime)

AGAIN please write this in java and please provide EXPLANATION of answer

Solutions

Expert Solution

1 dime = 10 cents

1 quarter = 25 cents

So we need to break up the cents given by user as input either as dime or quarter or combination of both.

Python Program

Code

cents = int(input("Please enter the change in Cents: "))

# example 65 cents
# quarter = 65/25 = 2
# dime = (65%25)/10 = 15/10 = 1
# cent = (65%25)%10 = (15)%10 = 5
# output = 2 quarter and 1 dime

quarter = int(cents/25) # 25 cents = 1 quarter
dime = int((cents%25)/10) # 10 cents = 1 dime
cents = (cents%25)%10

print(quarter,"quarters",dime,"dimes and",cents,"cents")

Test Output

Java Program

Code

import java.io.*;
import java.util.*;

public class Main
{
   public static void main(String[] args) {
  
   System.out.println("Please enter the change in cents: ");
String input = System.console().readLine();
  
int cents = Integer.parseInt(input);

// example 65 cents
// quarter = 65/25 = 2
// dime = (65%25)/10 = 15/10 = 1
// cent = (65%25)%10 = (15)%10 = 5
// output = 2 quarter and 1 dime
  
int quarter = cents/25; // 25 cents = 1 quarter
int dime = (cents%25)/10; // 10 cents = 1 dime
cents = (cents%25)%10;
  
       System.out.println(quarter + " quarters " + dime + " dimes and "+ cents + " cents");
   }
}

Test Output


Related Solutions

Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many times each person party in the day. For example def party_freq(dicto:dict) -> [(str,{(int,int,int): int})]: #code here input dict1 ={'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output [('Aaron', {(2000,5,20): 1, (2000,5,21): 1}), ('Baily', {(2000,5,20):...
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Use Python Write a function that takes a mobile phone number as a string and returns...
Use Python Write a function that takes a mobile phone number as a string and returns a Boolean value to indicate if it is a valid number or not according to the following rules of a provider: * all numbers must be 9 or 10 digits in length; * all numbers must contain at least 4 different digits; * the sum of all the digits must be equal to the last two digits of the number. For example '045502226' is...
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the total sum of the digits in the integers from 1 to that number inclusive. b. Write a program to input an integer n and call the above function in part a if n is positive, else give ‘Value must be Positive’ message. sample: Enter a positive integer: 1000000 The sum of the digits in the number from 1 to 1000000 is 27000001 Enter a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT