Exercise
Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a prime number is a number that has no divisors.). You can (and should!) use your answer to Exercise 4 to help you.Sample solution
There are many ways of solving this problem, so here are a sample solutions:The first, one possibility for using functions:
And this one is a different breakdown of functions to solve the problem. The strings between three
''' marks are comments in the code that describe what each function does.And here is a solution without using functions. It is also a correct solution that accomplishes the given task, just without the use of functions.
No comments:
Post a Comment