Seite 1 von 1

zahlen durch ihre ziffrenteilen

Verfasst: Dienstag 12. Oktober 2004, 09:45
von ich
hallo wie teilt man eine 3-stellige zahl durch ihre eigen drei ziffern(126 ist durch 1,2,6teilbar

Re: zahlen durch ihre ziffrenteilen

Verfasst: Dienstag 12. Oktober 2004, 10:33
von joe
Hallo!
ich hat geschrieben:hallo wie teilt man eine 3-stellige zahl durch ihre eigen drei ziffern(126 ist durch 1,2,6teilbar
Willst Du sowas?

Code: Alles auswählen

zahl = 113
zahl = str(zahl)
res = float(zahl) / int(zahl[0]) / int(zahl[1]) / int(zahl[2])
print res # Ausgabe 37.6666666667
Funktioniert nur, wenn die 3-stellige zahl positiv ist und keine 0 vorkommt.
joe

Verfasst: Dienstag 12. Oktober 2004, 10:39
von mawe
Hi!

Oder vielleicht so:

Code: Alles auswählen

zahl = 126
for i in str(zahl):
    print "%f / %f = %f" % (zahl, float(i), zahl/float(i))
Gruß, mawe