Python :: Aufgabe #7 :: Lösung #6

13 Lösungen Lösungen öffentlich
#7

Programmier-Basics: Centrechner

Anfänger - Python von Freki - 27.12.2012 um 14:51 Uhr
Schreiben Sie ein Programm, das eine Zahl in Cent einliest.
Das Programm soll die Anzahl von Dollar und Cent
wie folgt ausgeben:


Konsolenausgabe:

Geben Sie die Cent ein:
324
Das ergibt 3 Dollar und 24 Cent.


#6
vote_ok
von AnnaIhrs (460 Punkte) - 28.06.2016 um 00:39 Uhr
Quellcode ausblenden Python-Code
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
#
#>>>autor:      Sebastian Müller
#>>>licence:    GPL
#>>>contact:    mypythonmueller@gmail.com
#
#Schreiben Sie ein Programm, das eine Zahl in Cent einliest.
#Das Programm soll die Anzahl von Dollar und Cent
#ausgeben:

betr = 0

while not betr:
    try:
        betr = int(input("Bitte Geldbetrag in Cent eingeben. "))
    except:
        print("Eingabe war nicht korrekt")

betrz = betr

g500 = betr // 50000
betr -= g500 * 50000
g200 = betr // 20000
betr -= g200 * 20000
g100 = betr // 10000
betr -= g100 * 10000
g50 = betr // 5000
betr -= g50 * 5000
g20 = betr // 2000
betr -= g20 * 2000
g10 = betr // 1000
betr -= g10 * 1000
g5 = betr // 500
betr -= g5 * 500
e2 = betr // 200
betr -= e2 * 200
e1 = betr // 100
betr -= e1 * 100
c50 = betr // 50
betr -= c50 * 50
c20 = betr // 20
betr -= c20 * 20
c10 = betr // 10
betr -= c10 * 10
c5 = betr // 5
betr -= c5 * 5
c2 = betr // 2
betr -= c2 * 2


euro = betrz / 100
print(betrz, "Cent sind ", str(euro) + "Euro" )
print("Das sind:")
print("{0:<12} {1:<8} {2:<14}".format("Schein/Münze", "Anzahl", "Betrag"))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("500 Euro", g500, g500 * 500.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("200 Euro", g200, g200 * 200.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("100 Euro", g100, g100 * 100.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("50 Euro", g50, g50 * 50.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("20 Euro", g20, g20 * 20.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("10 Euro", g10, g10 * 10.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("5 Euro", g5, g5 * 5.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("2 Euro", e2, e2 * 2.0))
print("{0:>12} {1:8d} {2:14.2f}Euro".format("1 Euro", e1, e1 * 1.0))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("50 Cent", c50, c50 * 50))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("20 Cent", c20, c20 * 20))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("10 Cent", c10, c10 * 10))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("5 Cent", c5, c5 * 5))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("2 Cent", c2, c2 * 2))
print("{0:>12} {1:8d} {2:14.2f}Cent".format("1 Cent", betr, betr))

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben