Prime Number List
This exercise assumes you have already written the is_prime function in Programming Exercise 8. Write another program that displays all of the prime numbers from 1 through 100.
The program should have a loop that calls the is_prime function.
Prime Number List Python:
#The method 'is_prime' is used to
#displays all of the prime numbers
#from 1 through 100.
def is_prime(number):
if number < 2:
return False
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
return False
return True
# Loop through numbers from 1 to 100
print("Prime numbers from 1 through 100: ")
for number in range(1, 101):
if is_prime(number):
print(number)
Executed Output:
Prime numbers from 1 through 100:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97