![]() |
|
[challenge] change calculator - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [challenge] change calculator (/Thread-challenge-change-calculator) |
[challenge] change calculator - Inori - 12-22-2015 This is a pretty quick one. All you need to do is make a method that accepts a float and prints out the change values for it. Example IO: Code: #In:
calc(546.24)
#Out:
$100: 5
$50: 0
$20: 2
$10: 0
$5: 1
$2: 0
$1: 1
$0.25: 0
$0.10: 2
$0.05: 0
$0.01: 4Spoiler: Example Solution (python)Code: def calc(c):
for i in [100,50,20,10,5,2,1,0.25,0.10,0.05,0.01]:
print '$%s: \t%s'%(i,int(c//i))
c=c%iRE: [challenge] change calculator - Nil - 12-22-2015 Lmao! So I didn't know where to start, and I also didn't want to look for help. And thus, this masterpiece was born!!! Edit: I'll do something better later. The next piece of code I was about to submit would probably be more readable in machine. RE: [challenge] change calculator - m0dem - 12-22-2015 Python: Code: def calc(a):
for i in (100,50,20,10,5,2,1,.25,.10,.05,.01):
b,x=i,0
while b<=a: b,x=b+i,x+1
a-=x*i
print "$"+str(i),"-",xRE: [challenge] change calculator - Inori - 12-22-2015 (12-22-2015, 07:21 AM)God Wrote: Lmao! So I didn't know where to start, and I also didn't want to look for help. And thus, this masterpiece was born!!! Dude, that looks like some C shit
|