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
jenyasd209 [6]
2 years ago
13

# change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Do

llars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies
my code produces no output and i cant find why?


coin_change =int(input())

def coin_change(cents):
if cents <= 0:
print( 'Zero cents.')
else:
quarter = cents // 25
dime = (cents % 25) //10
nickle = cents % 25 % 10 // 5
penny = cents % 5



print (coin_change )
# produces no output
Computers and Technology
1 answer:
tiny-mole [99]2 years ago
3 0

Answer:

Explanation:

The Python code provided was not producing any output because you were never printing out the coin variables that you created. The following code adds the needed print statements using the right singular or plural coin name as needed.

cents = int(input())

 

def coin_change(cents):

   if cents <= 0:

       print('Zero cents.')

   else:

       quarter = cents // 25

       dime = (cents % 25) // 10

       nickle = cents % 25 % 10 // 5

       penny = cents % 5

   if quarter == 0 or quarter > 1:

       print(str(quarter) + " quarters")

   else:

       print(str(quarter) + " quarter")

   if dime == 0 or dime > 1:

       print(str(dime) + " dimes")

   else:

       print(str(dime) + " dime")

   if nickle == 0 or nickle > 1:

       print(str(nickle) + " nickels")

   else:

       print(str(nickle) + " nickel")

   if penny == 0 or penny > 1:

       print(str(penny) + " pennies")

   else:

       print(str(penny) + " penny")

coin_change(cents)

You might be interested in
def getCharacterForward(char, key): """ Given a character char, and an integer key, the function shifts char forward `key` steps
zhenek [66]

Answer:

  1. def getCharacterForward(char, key):  
  2.    charList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3.    if(len(char) > 1):
  4.        return None  
  5.    elif(not isinstance(key, int)):
  6.        return -1
  7.    else:
  8.        index = charList.find(char)
  9.        if(index + key <= 25):
  10.            return charList[index + key]
  11.        else:
  12.            return charList[(index + key)% 26]
  13. print(getCharacterForward("C", 4))
  14. print(getCharacterForward("X", 4))

Explanation:

Firstly, define a charList that includes all uppercase alphabets (Line 2). We presume this program will only handle uppercase characters.

Follow the question requirement and define necessary input validation such as checking if the char is a single character (Line 4). We can do the validation by checking if the length of the char is more than 1, if so, this is not a single character and should return None (Line 5). Next, validate the key by using isinstance function to see if this is an integer. If this is not an integer return -1 (Line 6 - 7).

Otherwise, the program will proceed to find the index of char in the charList using find method (Line 9). Next, we can add the key to index and use the result value to get forwarded character from the charList and return it as output (Line 11).

However, we need to deal a situation that the char is found at close end of the charList and the forward key steps will be out of range of alphabet list. For example the char is X and the key is 4, the four steps forward will result in out of range error. To handle this situation, we can move the last two forward steps from the starting point of the charList. So X move forward 4 will become B. We can implement this logic by having index + key modulus by 26 (Line 13).  

We can test the function will passing two sample set of arguments (Line 15 - 16) and we shall get the output as follows:

G

B

8 0
3 years ago
Write a python program to read four numbers (representing the four octets of an IP) and print the next five IP addresses. Be sur
sdas [7]

Answer:

first_octet = int(input("Enter the first octet: "))

second_octet = int(input("Enter the second octet: "))

third_octet = int(input("Enter the third octet: "))

forth_octet = int(input("Enter the forth octet: "))

octet_start = forth_octet + 1

octet_end = forth_octet + 6

if (1 <= first_octet <= 255) and (0 <= second_octet <= 255) and (0 <= third_octet <= 255) and (0 <= forth_octet <= 255):

   for ip in range(octet_start, octet_end):

       forth_octet = forth_octet + 1

       if forth_octet > 255:

           forth_octet = (forth_octet % 255) - 1

           third_octet = third_octet + 1

           if third_octet > 255:

               third_octet = (third_octet % 255) - 1

               second_octet = second_octet + 1

               if second_octet > 255:

                   second_octet = (second_octet % 255) - 1

                   first_octet = first_octet + 1

                   if first_octet > 255:

                       print("No more available IP!")

                       break

       print(str(first_octet) + "." + str(second_octet) + "." + str(third_octet) + "." + str(forth_octet))

else:

   print("Invalid input!")

Explanation:

- Ask the user for the octets

- Initialize the start and end points of the loop, since we will be printing next 5 IP range is set accordingly

- Check if the octets meet the restrictions

- Inside the loop, increase the forth octet by 1 on each iteration

- Check if octets reach the limit - 255, if they are greater than 255, calculate the mod and subtract 1. Then increase the previous octet by 1.

For example, if the input is: 1. 1. 20. 255, next ones will be:

1. 1. 21. 0

1. 1. 21. 1

1. 1. 21. 2

1. 1. 21. 3

1. 1. 21. 4

There is an exception for the first octet, if it reaches 255 and others also reach 255, this means there are no IP available.

- Print the result

8 0
3 years ago
If you use your computer primarily for telnet into a remote computer, will you have a large long distance telephone bill?
Nikolay [14]

If you use your computer primarily for telnet into a remote computer, a person will not have a large long distance telephone bill.

<h3>What is telnet used for?</h3>

Telnet is known to be a kind of a network protocol that is said to be used to virtually look into a computer and to give a two-way, working hand in hand and text-based communication channel that exist between two machines.

Note that, If you use your computer primarily for telnet into a remote computer, a person will not have a large long distance telephone bill because it does not apply in any way.

Learn more about telnet from

brainly.com/question/23640188

#SPJ1

4 0
2 years ago
Name the default<br><br>package of java​
melisa1 [442]
I think it should be Java of package instead
8 0
3 years ago
Who should NOT apply for financial aid?
Gnoma [55]

Answer: wealthy students should, not a must, apply for it. Not every student.

7 0
2 years ago
Other questions:
  • Look at the circuit shown in the figure above. Switch S1 is open as shown, and R1 and R2 each have a value of 100 k. If you conn
    11·1 answer
  • Consider a method defined with the header:
    13·1 answer
  • "The pkill command terminates _________."
    14·1 answer
  • Indexed sequential access, an index is more useful when the number of record is
    10·1 answer
  • Sedimentary rock formation occurs when igneous, metamorphic, or other sedimentary rocks are exposed to the unyielding forces of
    14·2 answers
  • the microsoft excel application is a _____ program. database word-processing spreadsheet desktop-publishing
    8·1 answer
  • What are personal skills?
    5·1 answer
  • Write a definition in your own words for Raster Graphic. Do not copy and paste please.
    12·1 answer
  • Technician A says that reprogramming a PCM using the J2534 system requires a factory scan tool, while Technician B says it requi
    14·1 answer
  • 1) SuperFetch is a memory-management technique that a) determines the type of RAM your system requires. b) makes the boot-up tim
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!