Challenge - 5 Problems
Prime Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of prime check for number 29
What is the output of this code when checking if 29 is prime?
DSA Python
def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True print(is_prime(29))
Attempts:
2 left
💡 Hint
Check divisors from 2 up to square root of the number.
✗ Incorrect
29 is a prime number because it has no divisors other than 1 and itself.
❓ Predict Output
intermediate2:00remaining
Output of prime check for number 1
What is the output of this code when checking if 1 is prime?
DSA Python
def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True print(is_prime(1))
Attempts:
2 left
💡 Hint
Numbers less than or equal to 1 are not prime.
✗ Incorrect
1 is not a prime number by definition.
🔧 Debug
advanced2:00remaining
Identify the error in prime check code
What error does this code produce when checking if 10 is prime?
DSA Python
def is_prime(n): if n <= 1 return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True print(is_prime(10))
Attempts:
2 left
💡 Hint
Check the line with the if statement for missing punctuation.
✗ Incorrect
The if statement is missing a colon, causing a SyntaxError.
❓ Predict Output
advanced2:00remaining
Output of prime check for number 25
What is the output of this code when checking if 25 is prime?
DSA Python
def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True print(is_prime(25))
Attempts:
2 left
💡 Hint
Check if 25 has divisors other than 1 and itself.
✗ Incorrect
25 is divisible by 5, so it is not prime.
🧠 Conceptual
expert2:00remaining
Why check divisors only up to square root?
Why does the prime check function only test divisors up to the square root of the number?
Attempts:
2 left
💡 Hint
Think about factor pairs and multiplication.
✗ Incorrect
If a number has a factor larger than its square root, it must pair with a smaller factor already checked.