Skip to content

Instantly share code, notes, and snippets.

@spaghettiSyntax
Created December 6, 2017 08:25
Show Gist options
  • Save spaghettiSyntax/84a1b2802146112374c1d46b8d9dd453 to your computer and use it in GitHub Desktop.
Save spaghettiSyntax/84a1b2802146112374c1d46b8d9dd453 to your computer and use it in GitHub Desktop.
Tony Gaddis Python: Coin Converter
# 11/6/17
# This file contains starter code for the following:
# Modify a previous program so that the user
# can use its code as many times as they wish.
CENTS_PER_QUARTER = 25 # a quarter is 25 cents
CENTS_PER_DIME = 10 # a dime is 10 cents
CENTS_PER_NICKEL = 5 # a nickel is 5 cents
# Set variable modification to repeat calculation if desired.
repeat = 'Y'
# The original program calculated the value of some coins.
while repeat == 'Y' or repeat == 'y':
# get input
print('We will convert coins to cents.')
quarters = int(input('How many quarters? '))
dimes = int(input('How many dimes? '))
nickels = int(input('How many nickels? '))
pennies = int(input('How many pennies? '))
# process the input,
# calculate the total value, in cents,
# of the coins input by the user.
cents = CENTS_PER_QUARTER * quarters \
+ CENTS_PER_DIME * dimes \
+ CENTS_PER_NICKEL * nickels \
+ pennies
# display the original coin quantities
# and the calculated value.
print( quarters, 'quarters',
dimes, 'dimes',
nickels, 'nickels',
pennies, 'pennies',
'is', cents, 'cents.')
repeat = input('Do you want to convert more coins? ' +
'(Enter y for yes): ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment