Finden Sie die Primzahl mit PythonPython

Python-Programme
Anonymous
 Finden Sie die Primzahl mit Python

Post by Anonymous »

Ich habe einen Ausschnitt, der Zahlen findet, die nicht bis 20 Co-Primes sind. Aber ich möchte das Gegenteil erreichen, d. H. Den Primzahlen drucken. Es sollte mit so etwas wie (((i%J)! == 0) & ((z%J)! == 0)) erreicht werden. Ich bin neu in Python und bin mir daher nicht sicher über die Syntax von "!". Kann jemand den Code so bearbeiten, dass er die Primzahlen druckt? < /P>

Code: Select all

#Finding co prime of a number (e.g.20)
k=0
z=20
for i in range(3,31):
for j in range(2,30):
if(((i%j)==0) & ((z%j)==0)):
k=k+1
if(k==1):
print(i) #the printed number is not co prime to 20
k=0
< /code>
Die Ausgabe des Code -Snippets ist folgt: < /p>
4
5
6
8
10
12
14
15
16
18
20
22
24
25
26
28
30

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post