
Beschaeftige mit gerade mit dem folgenden Projekt .... seid Ihr so lieb und kuckt mal darueber pls?
Code: Alles auswählen
from math import sqrt
list_up_to_onethousand = []
list_of_primes = []
for i in range(1000):
list_up_to_onethousand.append(i+1)
for i in list_up_to_onethousand:
sqrt_list_for_i = []
sqrt_list_for_i.append(int(sqrt(i+1)))
for n in sqrt_list_for_i:
if i % n == 0:
continue
else:
list_of_primes.append(i)
#print(list_up_to_onethousand)
print(list_of_primes)
Das Ergebnis ist dabei Mangelhaft ..... "[3, 5, 7, 8, 10, 11, 13, 14, ...]"
Meine zwei Fragen:
- Wo ist die 1 und die 2 hin?
- zur 8, 10, 14, ...: ich vermute, dass die eingerueckte for-Zeile 'n in sqrt_list_for_i' falsch eingerueckt ist oder den falschen Bezug aufweist? Eigentlich will ich ja, dass fuer 'i' in 'list_up_to_onethousand' jeweils die Pruefung mit 'n' stattfindet und nicht andersherum ........


GlG und schonmal Danke =D c.b.