Prime Numbers in Python - tricks to make your program find them faster

preview_player
Показать описание
A basic introduction to searching for prime numbers in Python and looking at a couple of tricks to improve the search space of your code.
Could be useful for A level students as this might be the sort of thing asked in a timed programming task!

import time, math
number = int(input("Enter number to check if it's prime"))
prime = True
if number % i == 0:
prime = False
break
if prime == True:
print(number ,"is a prime number")
else:
print(number ,"is NOT a prime number")
print("Seconds:"+str(end_time - start_time))
Рекомендации по теме
Комментарии
Автор

This approach is actually evidently cooler than all the videos i have seen in last month of me learning Python from youtube... Thanks a lot...

hirenmakwana
visit shbcf.ru