| Python 2.2 für Einsteiger | ||
|---|---|---|
| <<< Previous | Einführung anhand von Beispielen | Next >>> |
#!/usr/bin/python
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print n, 'ist gleich', x, '*', n/x
break
else:
print n, 'ist eine Primzahl'
# 2 ist eine Primzahl
# 3 ist eine Primzahl
# 4 ist gleich 2 * 2
# 5 ist eine Primzahl
# 6 ist gleich 2 * 3
# 7 ist eine Primzahl
# 8 ist gleich 2 * 4
# 9 ist gleich 3 * 3
| <<< Previous | Home | Next >>> |
| HTTP - Client | Up | Primzahlen Sieb des Eratosthenes |