Check if Number is Prime
📖 Scenario: You are helping a friend who wants to check if a number is prime. A prime number is a number greater than 1 that has no divisors other than 1 and itself.Imagine you have a list of numbers and want to find out which ones are prime.
🎯 Goal: Build a simple program that checks if a given number is prime by testing divisibility from 2 up to the number minus one.
📋 What You'll Learn
Create a variable called
number with the exact value 29.Create a variable called
is_prime and set it to True.Use a
for loop with variable i to check divisors from 2 to number - 1.Inside the loop, if
number is divisible by i, set is_prime to False and break the loop.Print
"Prime" if is_prime is True, otherwise print "Not Prime".💡 Why This Matters
🌍 Real World
Prime numbers are important in cryptography, computer security, and coding theory.
💼 Career
Understanding prime checking helps in algorithm design and problem solving in software development.
Progress0 / 4 steps