Question
z(Pyhton)For #17-18, you'll get to practice with your loops using sentinels. Assume any given number IS prime, then as you go through the loop trying
z(Pyhton)For #17-18, you'll get to practice with your loops using sentinels. Assume any given number IS prime, then as you go through the loop trying to divide by all the possible factors, you can terminate the first time the number DOES divide evenly - proving that it is NOT prime. All you have to do is turn in your work for #18 (it includes everything from #17 anyway). 30 points
#17 Prime Numbers
A prime number is a number that is only evenly divisble by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. THe number is 6, how ever, is not prime because it can be divided evenly by 1,2,3,and 6. Write a BOolean function name is_prime which takes an integer as an argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.
TIP: Recall that the % operator divides one number ny another and returns the remainder of the division. In an expression such a num1 % num2, the % operator will return () if num1 is evenly divisible by num2.
#18 Prime NUmber List
THis excercise assums you have already written the is_prime function in Programming Exercise 17. Write another program that displays all of the pime numbers from 1 to 100. This program should have a loop that calls is+prime function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started