Kurs:Python/Material/Scripts/Römische Zahlen

Aus Wikiversity

Eine Eingabe in eine römische Zahl umwandeln.

Ein erstes, ziemlich dummes Skript:

zahl = input ("Geben Sie eine Zahl ein: ")

if zahl < 1 or zahl > 9:
    print "Ihre Eingabe ist ausserhalb des erlaubten Bereichs."

roemischeZahl = ""

if zahl == 1:
    roemischeZahl = roemischeZahl + "I"
elif zahl == 2:
    roemischeZahl = roemischeZahl + "II"
elif zahl == 3:
    roemischeZahl = roemischeZahl + "III"
elif zahl == 4:
    roemischeZahl = roemischeZahl + "IV"
elif zahl == 5:
    roemischeZahl = roemischeZahl + "V"
elif zahl == 6:
    roemischeZahl = roemischeZahl + "VI"
elif zahl == 7:
    roemischeZahl = roemischeZahl + "VII"
elif zahl == 8:
    roemischeZahl = roemischeZahl + "VIII"
elif zahl == 9:
    roemischeZahl = roemischeZahl + "IX"    

print roemischeZahl