+ 6

how to print prime numbers using python code??

i have some ideas but they are not valid..

31st Jul 2019, 10:11 AM
Prasad
Prasad - avatar
4 ответов
+ 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.
31st Jul 2019, 10:43 AM
Lothar
Lothar - avatar
+ 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
31st Jul 2019, 10:33 AM
Muhammad Shehzad
Muhammad Shehzad - avatar
+ 5
Anyway, it is a good idea if you share your code with us.
31st Jul 2019, 10:31 AM
Lothar
Lothar - avatar
+ 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.
31st Jul 2019, 10:37 PM
Mateusz R
Mateusz R - avatar