Problem Statement:
Write a Python program to find:
- The first two-digit prime number.
- The last two-digit prime number.
first = 0
last = 0
# Find first two-digit prime
for n in range(10, 100):
count = 0
for i in range(1, n + 1):
if n % i == 0:
count += 1
if count == 2:
first = n
break
# Find last two-digit prime
for n in range(99, 9, -1):
count = 0
for i in range(1, n + 1):
if n % i == 0:
count += 1
if count == 2:
last = n
break
print("First Prime:", first)
print("Last Prime:", last)
First Prime: 11
Last Prime: 97
This problem helped me understand how loops, conditions, and the modulus operator work together to solve logical problems.
One important thing I learned is that we should not directly jump into coding. First, understand the problem, perform a dry run, develop the logic, and then convert it into a Python program.
Top comments (0)