Hey, ich bin noch ein totaler Anfänger im Thema programmieren und wollte nur zur Übung mal die Eulerprobleme mit Python versuchen. Meine jetzige Aufgabe lautet, die kleinstmögliche Zahl zu finden, die sich gerade durch die Zahlen 1 - 20 teilen lässt.
Ich habe einen Code geschrieben, der das sogar hinbekommen hat:
for i in range(1, 100000000):
if (i % 1 == 0 and i % 2 == 0 and i % 3 == 0 and i % 4 == 0 and i % 5 == 0
and i % 6 == 0 and i % 7 == 0 and i % 8 == 0 and i % 9 == 0 and i % 10 == 0
and i % 11 == 0 and i % 12 == 0 and i % 13 == 0 and i % 14 == 0 and i % 15 == 0
and i % 16 == 0 and i % 17 == 0 and i % 18 == 0 and i % 19 == 0 and i % 20 == 0):
print (i)
Wie ihr bestimmt sofort seht, ist dieser Code verdammt hässlich.
Einfach für meine Verbesserung würde ich gerne wissen, wie man das Problem "eleganter" lösen kann, ohne Modulo für alles einzeln anwenden zu müssen. Mir ist da nichts eingefallen :/
Kann mir bitte wer Tipps geben?
Ich habe einen Code geschrieben, der das sogar hinbekommen hat:
for i in range(1, 100000000):
if (i % 1 == 0 and i % 2 == 0 and i % 3 == 0 and i % 4 == 0 and i % 5 == 0
and i % 6 == 0 and i % 7 == 0 and i % 8 == 0 and i % 9 == 0 and i % 10 == 0
and i % 11 == 0 and i % 12 == 0 and i % 13 == 0 and i % 14 == 0 and i % 15 == 0
and i % 16 == 0 and i % 17 == 0 and i % 18 == 0 and i % 19 == 0 and i % 20 == 0):
print (i)
Wie ihr bestimmt sofort seht, ist dieser Code verdammt hässlich.
Einfach für meine Verbesserung würde ich gerne wissen, wie man das Problem "eleganter" lösen kann, ohne Modulo für alles einzeln anwenden zu müssen. Mir ist da nichts eingefallen :/
Kann mir bitte wer Tipps geben?