Skip to content

Instantly share code, notes, and snippets.

@NDS1608
Created January 29, 2018 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NDS1608/6f4a914c550ccdfb9db9dba618322eea to your computer and use it in GitHub Desktop.
Save NDS1608/6f4a914c550ccdfb9db9dba618322eea to your computer and use it in GitHub Desktop.
change machine test
'''
CHANGE MACHINE
'''
# FUNCTIONS
def calcTtl(x, y):
# Total = amount x price
return x * y
def calcChg(w, z):
# Change = payment - total
return w - z
def calcCn(x):
#x = change
d = x / 1
x %= 1
q = x / 0.25
x %= 0.25
dM = x / 0.10
x %= 0.10
n = x / 0.05
x %= 0.05
p = x / 0.01
x %= 0.01
print('You are handed: ')
if d >= 2:
print(str(int(d)) + ' dollar(s)')
elif d == 1:
print(str(int(d)) + ' dollar')
if q >= 0.26 or q < 0.25:
print(str(int(q)) + ' quarter(s)')
elif q == 1:
print(str(int(q)) + ' quarter')
if dM >= 0.11 or dM < 0.10:
print(str(int(dM)) + ' dime(s)')
elif dM == 1:
print(str(int(dM)) + ' dime')
if n >= 0.06 or n < 0.05:
print(str(int(n)) + ' nickel(s)')
elif n == 1:
print(str(int(n)) + ' nickel')
if p >= 0.02 or p <0.01:
print(str(int(p)) + ' pennies')
elif p == 1:
print(str(int(p)) + ' penny')
return('Thank you for your purchase!')
def chgFltr(x, y):
# payment, total
if x < y:
print('Insfficient funds')
else:
print('Your change is $%.2f' % calcChg(pY, calcTtl(a, pR)))
print(calcCn(calcChg(pY,calcTtl(a,pR))))
# PROCESS
loop_func = True
while loop_func :
break
cart = 0
print('\n Hello, we sell bananas for $1.50, apples for $.75, and oranges for $2.15')
selec = input('please select your product; type b for banana, a for apple, and o for oranges: ')
if selec == 'b':
pR = 1.50
elif selec == 'a':
pR = 0.75
elif selec == 'o':
pR = 2.15
else:
print('invalid input')
continue
amount =float(input('How many would you like: '))
a = amount
cart = cart + (a * pR)
print('Your total is: %.2f' % calcTtl(a,pR))
chk_out = input('Are you ready to check out? yes/no: ')
if chk_out == 'no':
add_pR = input('What else would you like?: ')
if add_pR == 'b':
add_Amt = float(input('How many?: '))
cart = str(cart + (1.50 * add_Amt))
elif add_pR == 'a':
add_Amt = float(input('How many?: '))
cart = str(cart + (0.75 * add_Amt))
else:
add_Amt = float(input('How many?: '))
cart = str(cart + (2.15 * add_Amt))
else:
pass
cart = float(cart)
print('Your cart total is currently $%.2f' % cart)
print('How will you be paying?')
payment = float(input('Enter dollar amount $'))
pY = payment
chgFltr(pY,calcTtl(a,pR))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment