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
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
What is the first view you place in your drawing?
Answers: 1
question
Computers and Technology, 23.06.2019 00:20
The open systems interconnection (osi) reference model: defines standards for many aspects of computing and communications within a network. is a generic description for how computers use multiple layers of protocol rules to communicate across a network. defines standards for wireless local area network (wlan) communication protocols. details the advantages and disadvantages of various basic network cabling options.
Answers: 1
question
Computers and Technology, 24.06.2019 00:50
3. what is the output of the following statements? temporary object1; temporary object2("rectangle", 8.5, 5); temporary object3("circle", 6, 0); temporary object4("cylinder", 6, 3.5); cout < < fixed < < showpoint < < setprecision(2); object1.print(); object2.print(); object3.print(); object4.print(); object1.set("sphere", 4.5, 0); object1.print();
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, 15.06.2021 21:30
question
English, 15.06.2021 21:30
question
Mathematics, 15.06.2021 21:30
question
Mathematics, 15.06.2021 21:30