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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 13:20, mj200442
Raymond ozzie, the software designer who was critical in the development of lotus notes, was able to dictate the terms under which ibm acquired lotus. this illustrates that he had bargaining power based on the cost required by the firm to replace him.
Answers: 3
image
Computers and Technology, 22.06.2019 07:30, DivineMemes420
What type of computer network ensures high security ?
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, joshualoz5414
Acase study allows a more detailed look at the life of a single subject than any other study.
Answers: 3
image
Computers and Technology, 23.06.2019 02:00, mayapril813
Consider the following function main: int main() { int alpha[20]; int beta[20]; int matrix[10][4]; . . } a. write the definition of the function inputarray that prompts the user to input 20 numbers and stores the numbers into alpha. b. write the definition of the function doublearray that initializes the elements of beta to two times the corresponding elements in alpha. make sure that you prevent the function from modifying the elements of alpha. c. write the definition of the function copyalphabeta that stores alpha into the first five rows of matrix and beta into the last five rows of matrix. make sure that you prevent the function from modifying the elements of alpha and beta. d. write the definition of the function printarray that prints any onedimensional array of type int. print 15 elements per line. e. write a c11 program that tests the function main and the functions discussed in parts a through d. (add additional functions, such as printing a two-dimensional array, as needed.)
Answers: 3
You know the right answer?
Writing a Python program to calculate change. This is what I have: val = int(input())

d...

Questions in other subjects: