Python Quiz Master
Test your Python knowledge with our interactive MCQ platform. Challenge yourself with questions from beginner to advanced levels.
753
Questions
13
Topics
75%
Success Rate
3
Difficulty Levels
Start Your Quiz
Beautiful Python Code Examples
Our interactive quizzes include well-formatted Python code with syntax highlighting
prime_numbers.py
line-numbers
def is_prime(n: int) -> bool:
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def get_primes(limit: int) -> list[int]:
"""Get all prime numbers up to limit."""
return [n for n in range(2, limit + 1) if is_prime(n)]
# Example usage
prime_numbers = get_primes(100)
print(f"Prime numbers up to 100: {prime_numbers}")