CSC111 Homework 2 Solutions 2014

From dftwiki3
Revision as of 11:20, 20 February 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- =Problem #1= <br /> <source lang="python"> #hw2a.py #Zoey Jingyi Sun (ch) #Yipeng Lai (bq) #Solution Program for Problem#1 in Homework#2 # #This program is to br...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 11:20, 20 February 2014 (EST)


Problem #1


#hw2a.py
#Zoey Jingyi Sun (ch)
#Yipeng Lai (bq)
#Solution Program for Problem#1 in Homework#2
#
#This program is to breakdown the money entered by the user into bills and coins
#-------------------------------------------------------------------------------
#

#Get user input
amount=float(input( "Please enter the amount of money you want to withdraw:"))

#Print top bar
bar="+"+"-"*36+"+"
length=len(bar)
print(bar)

print("|","Total amount withdrawn: ","$%7.2f" % amount," |")
print("|"+" "*(length-2)+"|")

bill=int(amount)
coin=int((amount-bill)*100)

#Calculate bills numbers
BILL1=20
BILL2=10
BILL3=5
BILL4=1

#Calculate the numbers of $20-bill(s)
noBill= bill // BILL1
leftover= bill % BILL1
line1=" %2d" % noBill+" $20-bill(s)"
print ("|"+line1+" "*(length-len(line1)-2)+"|")

#Calculate the numbers of $10-bill(s)
noBill= leftover // BILL2
leftover= leftover % BILL2
line1=" %2d" % noBill+" $10-bill(s)"
print ("|"+line1+" "*(length-len(line1)-2)+"|")

#Calculate the numbers of $5-bill(s)
noBill= leftover // BILL3
leftover= leftover % BILL3
line1=" %2d" % noBill+" $5-bill(s)"
print ("|"+line1+" "*(length-len(line1)-2)+"|")

#Calculate the numbers of $1-bill(s)
noBill= leftover // BILL4
leftover= leftover % BILL4
line1=" %2d" % noBill+" $5-bill(s)"
print ("|"+line1+" "*(length-len(line1)-2)+"|")

#Print middle bar
print ("|"+"-"*19+" "*(length-21)+"|")

#Calculation of coins numbers
COIN1=25
COIN2=10
COIN3=5
COIN4=1

#Calculate the numbers of quarter(s)
noCoin= coin // COIN1
leftover= coin % COIN1
line2=" %2d" % noCoin+" quarter(s)"
print ("|"+line2+" "*(length-len(line2)-2)+"|")

#Calculate the numbers of dime(s)
noCoin= leftover // COIN2
leftover= leftover % COIN2
line2=" %2d" % noCoin+" dime(s)"
print ("|"+line2+" "*(length-len(line2)-2)+"|")

#Calculate the numbers of nickel(s)
noCoin= leftover // COIN3
leftover= leftover % COIN3
line2=" %2d" % noCoin+" nickel(s)"
print ("|"+line2+" "*(length-len(line2)-2)+"|")

#Calculate the numbers of cent(s)
noCoin= leftover // COIN4
leftover= leftover % COIN4
line2=" %2d" % noCoin+" cent(s)"
print ("|"+line2+" "*(length-len(line2)-2)+"|")

#Print bottom bar
print(bar)