subject

Writing a Python program to calculate change. This is what I have: val = int(input())

dollar = 100
quarter = 25
dime = 10
nickel = 5
penny = 1

if val <= 0:
print('No change')

# dollars
num_dollar = val // dollar
if num_dollar > 1:
print('%d Dollars' % num_dollar)
elif dollar == 1:
print('%d Dollar' % num_dollar)
val = val - (num_dollar * dollar)

# quarters
num_quarter = val // quarter
if num_quarter > 1:
print('%d Quarters' % num_quarter)
elif quarter == 1:
print('%d Quarter' % num_quarter)
val = val - (num_quarter * quarter)

# dimes
num_dime = val // dime
if num_dime > 1:
print('%d Dimes' % num_dime)
elif dime == 1:
print('%d Dime' % num_dime)
val = val - (num_dime * dime)

# nickels
num_nickel = val // nickel
if num_nickel > 1:
print('%d Nickels' % num_nickel)
elif nickel == 1:
print('%d Nickel' % num_nickel)
val = val - (num_nickel * nickel)

# pennies
num_penny = val // penny
if num_penny > 1:
print('%d Pennies' % penny)
elif penny == 1:
print('%d Penny' % penny)
val = val - (num_penny * penny)

No matter what input I use, for example 350, my output will be:
3 Dollars
2 Quarters
1 Penny

Or 250
2 Dollars
2 Quarters
1 Penny

I can't figure out what I need to do in order to make the extra penny problem go away. Any help is appreciated.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 09:10
Effective character encoding requires standardized code. compatible browsers. common languages. identical operating systems.
Answers: 1
question
Computers and Technology, 24.06.2019 05:30
Why is hard disk space important to an audio engineer? why are usb ports and firewire ports useful for an audio engineer? explain in 2-3 sentences. (3.0 points) here's a list of different audio software: ableton live apple inc.'s garageband apple inc.'s logic studio digidesign's pro tools propellerhead sofware's reason sony creative software's acid pro steinberg cubase steinberg nuendo choose one of the software programs listed above, and then go to that software program's web site. read about what the software program is used for, and then write 4-5 sentences about what you learned. (10.0 points) which type of software license is the most limiting? why? explain in 2-3 sentences. (3.0 points) when sending a midi channel voice message, how can you control the volume of the sound? explain in 2-3 sentences. (4.0 points)
Answers: 1
question
Computers and Technology, 25.06.2019 07:00
Afile named data.txt contains an unknown number of lines, each consisting of a single integer. write some code that creates two files, dataplus.txt and dataminus.txt, and copies all the lines of data1.txt that have positive integers to dataplus.txt, and all the lines of data1.txt that have negative integers to dataminus.txt. zeros are not copied anywhere.
Answers: 2
question
Computers and Technology, 25.06.2019 22:00
Which of the following describes the operating system? a. it commands and controls all of the hardware and other software applications b. it contains the circuitry that processes the information coming into the computer c. it is one of the physical components of the computer d. it can be divided into two categories: input and output
Answers: 1
You know the right answer?
Writing a Python program to calculate change. This is what I have: val = int(input())

d...
Questions
question
Mathematics, 26.04.2021 22:20
question
Mathematics, 26.04.2021 22:20
question
Mathematics, 26.04.2021 22:30
question
Mathematics, 26.04.2021 22:30
question
Mathematics, 26.04.2021 22:30
question
Mathematics, 26.04.2021 22:30
Questions on the website: 13722361