+ 6
how to print prime numbers using python code??
i have some ideas but they are not valid..
4 odpowiedzi
+ 7
ok - but this not your code. Anyway you can learn from it and so try to make your own code and test it. If you need help at this point we can help you.
I forgot to give you a source where you can flnd more information about primes:
https://en.m.wikipedia.org/wiki/Prime_number
Go to chapter Computational methods.
+ 8
# Python program to display all the prime numbers within an interval
# change the values of lower and upper for a different result
lower = 900
upper = 1000
# uncomment the following lines to take input from the user
#lower = int(input("Enter lower range: "))
#upper = int(input("Enter upper range: "))
print("Prime numbers between",lower,"and",upper,"are:")
for num in range(lower,upper + 1):
# prime numbers are greater than 1
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
https://www.programiz.com/python-programming/examples/prime-number-intervals
+ 5
Anyway, it is a good idea if you share your code with us.
+ 1
Google for Sieve of Eratosthenes. it's a little bit faster algorithm than mentioned above and there is already multiple other implementations done to compare.