Python Loops
Part 1: Determine if a number is Prime
A positive whole number, n > 2, is prime if no number between 2 and the square root of (inclusive) evenly divides n. Write a program that accepts a value of n as input, and determines if the value is prime. If n is no prime, your program should quit as soon as it finds a value that evenly divides n.
Part 2: Lists of Prime Numbers
Modify your program to find every prime number less than or equal to n. [Hint: add an outer loop]
Part 3: Goldbach Conjecture (BONUS 20 pts Extra Credit)
The Goldbach conjecture asserts that every even number is the sum of two prime numbers. Write a program that gets a number from the user, checks to make sure that it is even, then finds two prime numbers that add up to the number.
Get Free Quote!
409 Experts Online