Menu

Python Day 16: Solving Mathematical Problems Using Functions and Loops
📰

Python Day 16: Solving Mathematical Problems Using Functions and Loops

DEV Community: beginners·Vasanthakumari N·13 days ago
#ktkYzHuK
#devtobeginners#devto#dev#calling#print
Long article (956 words) — no AI summary yet.
Reading 0:00
15s threshold

1. Find the Smallest and Biggest Two-Digit Prime Numbers

Problem: Write a Python program to find the smallest and biggest two-digit prime numbers.

A prime number has exactly two divisors: 1 and itself.

Step 1: Create a Function to Check Prime Numbers

def find_prime ( no ) : #12 div = 2 while div <= no // 2 : #10 Times if no % div == 0 : return False div += 1 else : return True

Enter fullscreen mode

Exit fullscreen mode

The function returns:

True if the number is prime.

False if the number is not prime.

Step 2: Find the Smallest and Biggest Prime Numbers

no = 11 first = True last_prime = no while no <= 99 : result = find_prime ( no ) #Calling Statement if result == True and first == True : print ( "First Prime Number" , no ) first = False elif result == True : last_prime = no #13 17 19 23 29 31 37 43 47 no += 2

print ( "Last Prime Number is" , last_prime )

Enter fullscreen mode

Exit fullscreen mode

Output:

First Prime Number: 11 Last Prime Number: 97

Enter fullscreen mode

Exit fullscreen…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.