Python Lösung
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #!/usr/bin/python
# coding: utf-8
def stueckle(betrag):
einheiten = {"euro":[500,200,100,50,20,10,5,2,1],
"cent":[50,20,10,5,2,1]}
euro = int(betrag[:-3])
cent = int(betrag[-2:])
print "Stückle %i € und %i cent"%(euro, cent)
def split_(no, parts, template):
out = {}
rest = no
for part in parts:
out[part] = rest/part
rest %= part
print "%i %ier, noch %s Euro"%(out[part], part, template%rest)
parts = {}
for betrag, einheit, template in ((euro, "euro", "%i."+str(cent)),
(cent, "cent", "0.%i")):
print einheit
parts[einheit] = split_(betrag, einheiten[einheit], template)
|
erstellt am 2.12.2008 21:37, zuletzt gendert am 2.12.2008 21:37
