1. Prime numbers within 100:
result = []
for i in range(2,101):
for j in range(2,i - 1):
if i % j == 0:
break
else:
result.append(i)
print(result)
Encapsulated into a function:
import math
def is_prime(n):
if n == 1:
return False
elif n == 2:
return True
else:
for i in range(2,int(math.sqrt(n) + 1)):
if n % i == 0:
return False
return True
for i in range(1,101):
if is_prime(i):
print(i,end = ' ')