Question

I have this code for python: num = int(input()) if num == 0: print('No change') else:...

I have this code for python:

num = int(input())

if num == 0:
print('No change')
else:
dol = num // 100
num %= 100
Quarters = num // 25
num %= 25
Dimes = num // 10
num %= 10
Nickels = num // 5
num %= 5
Pennies = num

if dol > 0:
if dol == 1:
print('1 Dollar')
if Dollars > 1:
print(dol,'Dollars')

if Quarters > 0:
if Quarters == 1:
print('1 Quarter')
if Quarters > 1:
print(Quarters,'Quarters')

if Dimes > 0:
if Dimes == 1:
print('1 Dime')
if Dimes > 1:
print(Dimes,'Dimes')
if Nickels > 0:
if Nickels == 1:
print('1 Nickel')
if Nickels > 1:
print(Nickels,'Nickels')
if Pennies > 0:
if Pennies == 1:
print('1 Penny')
if Pennies > 1:
print(Pennies,'Pennies')

When I put 0 as the input, I keep getting this error: "No change Traceback (most recent call last): File "main.py", line 16, in if dol > 0: NameError: name 'dol' is not defined"

what am I doing wrong? Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

num = int(input())

if num == 0:

  print('No change')

else:

  dol = num // 100

  num %= 100

  Quarters = num // 25

  num %= 25

  Dimes = num // 10

  num %= 10

  Nickels = num // 5

  num %= 5

  Pennies = num

  if dol > 0:

    if dol == 1:

      print('1 Dollar')

#Dollors not defined

    if dol > 1:

      print(dol,'Dollars')

  if Quarters > 0:

    if Quarters == 1:

      print('1 Quarter')

    if Quarters > 1:

      (Quarters,'Quarters')

  if Dimes > 0:

    if Dimes == 1:

      print('1 Dime')

    if Dimes > 1:

      print(Dimes,'Dimes')

  if Nickels > 0:

    if Nickels == 1:

      print('1 Nickel')

    if Nickels > 1:

      print(Nickels,'Nickels')

  if Pennies > 0:

    if Pennies == 1:

      print('1 Penny')

    if Pennies > 1:

      print(Pennies,'Pennies')

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
I have this code for python: num = int(input()) if num == 0: print('No change') else:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • I need to change this python program into one that counts back the LEAST AMOUNT OF...

    I need to change this python program into one that counts back the LEAST AMOUNT OF COINS. Ex: if i input 44 as my change, how can i make it show 4 dimes and 4 pennies instead of 1 quarter, a dime, and 9 pennies? heres my code so far in PYTHON " cents=int(input("Please enter the change in Cents: ")) Quarter= int(cents/25)#25cents=1 Quarter Dime =int (cents%25/10)# 10 cents=1 Dime cents =(cents%25)%10 print(Quarter,"quarters",Dime,"dimes and",cents,"cents") "

  • I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at...

    I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at all, it is just left blank. package edu.wit.cs.comp1050; /** * Solution to the third programming assignment * When it runs it outputs the amount in quarters, dimes, nickels and pennies * * @author Rose Levine * */ import java.util.Scanner; public class PA1c {       /**    * Error message to display for negative amount    */    public static final String ERR_MSG =...

  • Write a program with total change amount as an integer input, and output the change using...

    Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • In Python 3, Implement a program that directs a cashier how to give change. The program...

    In Python 3, Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies, for example 526 instead of 5.26. Enter the amount due in pennies: 828 Enter the amount received from the customer in...

  • I made this C program to count change and make a slip saying the exact dollar...

    I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong? #include<stdio.h> int main(void) { char first, last; int pennies; int nickels; int dimes; int quarters; int loonies; int change; int t_dollars; int t_cents; printf("Type in your 2 initials and press return> "); scanf("%c%c",&first,&last); printf("%c%c please enter in your...

  • Develop a solution that would return the fewest coins in change from a purchase of under one doll...

    this activity It must be done Flowchart PAC and IPO Develop a solution that would return the fewest coins in change from a purchase of under one dollar. (Incude pennies, nickels, dimes, quarters, and half dollars.) Example: purchase 63 change 370 I quarter 1 dime coins 2 pennies Develop a solution that would return the fewest coins in change from a purchase of under one dollar. (Incude pennies, nickels, dimes, quarters, and half dollars.) Example: purchase 63 change 370 I...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT