Computers and Technology

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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, araminaara691
How can a user open a blank presentation? 1.on the file menu, click new, and then click recent templates 2.on the file menu, click new, and then click blank presentation 3. on the view menu, click templates, and then click recent templates 4. on the view menu, click samples, and then click blank presentation
Answers: 1
image
Computers and Technology, 23.06.2019 18:00, yedida
File account. java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
image
Computers and Technology, 24.06.2019 11:20, tiffanibell71
Colby works as a shipping clerk for a major package delivery service. some of his daily tasks include tracking shipments and entering orders. which aspect of the information technology cluster would he most likely be trained in? a. networkingb. databasesc. hardwared. software
Answers: 2
image
Computers and Technology, 24.06.2019 16:00, altstattlana
Read these lines from beowulf. often scyld scefing seized mead-benches from enemytroops, from many a clan, he terrified warriors, even thoughfirst he was found a waif, best explains why the author includes this information in theexposition? a. to emphasize that a hero must learn to be fierceb. to remember the famous story of a popular heroc. to express sadness about losing the old heroesd. to see whether people still respect the old heroes
Answers: 1
Do you know the correct answer?
Writing a Python program to calculate change. This is what I have: val = int(input())

d...

Questions in other subjects:

Konu
English, 18.03.2021 01:20