Home > other >  See what is wrong, quick collapse
See what is wrong, quick collapse

Time:10-22

Screening method by using a list of primes
Problem description: write a program, enter a natural number greater than 2, then the output is less than the number of all prime number list

Def sushu (num) :
LST=[]
For I in range (2, num) :
Flag=1
For j in range (2, I) :
If I % j==0:
Flag=0
Break

The if flag:
LST. Append (I)
Print (LST)


Num=input (" please input a natural number greater than 2: ")
Sushu (num)

CodePudding user response:

 def sushu (num) : 
LST=[]
For I in range (2, num) :
Flag=1
For j in range (2, I) :
If I % j==0:
Flag=0
Break

The if flag:
LST. Append (I)
Print (LST)


Num=int (input (" please input a natural number greater than 2: "))
Sushu (num)
  • Related