RE: [challenge] change calculator 12-22-2015, 07:35 PM
#4
(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!!!
Warning: Embarrassingly funny code ahead!
Spoiler: Python 3+
Code:MONEY = 345 def main(): index = 0 list1 = [100, 50, 20, 10, 5, 1, .25, .10, .05, .01] list2 = [0]*10 list2 = change(MONEY, index, list1, list2) pretty_display(list1, list2, index) def change(MONEY, index, list1, list2): for x in list1: ch = MONEY // list1[index] list2[index] = int(ch) MONEY = MONEY - (ch * list1[index]) index+=1 return list2 def pretty_display(list1, list2, index): for x in list2: print('$', list1[index], '\t',': ', x, sep = '') index+=1 main()
So obviously you just change the money variable to get your desired results. And it just prints out a list in order of the change values. I didn't use a two dollar bill value.
But hey! It works.
Edit: No longer prints out list, modified for pretty display! Definitely now a industrial standard program! haha. Anyway, thought it was easy until I started typing and realized I couldn't find an elegant approach. Feel like I just brute-forced my way to a solution. If anyone has any criticism, such as seeing something that could easily be improved or changed then by all means point it out.
Edit2: Actually, If I add any amount of dollars with something under 5 cents (300.04) it prints out one less penny. I'll fix that in the morning.
Dude, that looks like some C shit
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.

















![[+]](https://sinister.li/images/modern/collapse_collapsed.png)