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, 22.06.2019 09:00
Which best describes the condition under which the unicode output is the same as plain text?
Answers: 3
question
Computers and Technology, 23.06.2019 03:50
Iam a bacterium. i cause stomach cramps and diarrhea. i am caused by eating rotten foodssuch as chicken, fish, or eggs. sometimes turtles carry my bacteria.what am i?
Answers: 2
question
Computers and Technology, 23.06.2019 18:00
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
Answers: 1
question
Computers and Technology, 23.06.2019 18:40
How does is make you feel when you're kind to others? what are some opportunities in your life to be more kind to your friends and loved ones? imagine a world where kindness has be outlawed. how would people act differently? would your day-to-day life change significantly? why or why not?
Answers: 2
You know the right answer?
Writing a Python program to calculate change. This is what I have: val = int(input())

d...
Questions
question
History, 22.10.2021 23:00
question
Mathematics, 22.10.2021 23:00
question
Mathematics, 22.10.2021 23:00
Questions on the website: 13722363