Exercise: Primeness (Function)

Modify the prime number detection program from here or here as follows.

  • Push the prime number checking algorithm into a function. (is_prime() is a likely name for the function.)

    • The function takes the number-to-test-for-primeness as parameter.

    • The function returns whether the number-to-check is prime (a boolean value)

  • The rest of the program (taking the number from the commandline, or using input() to prompt the user for the number) remains intact. The only change is that the new function is called with the number as parameter, rather than implement the algorithm in top level code.

Dependencies

cluster_python Python cluster_python_basics Basics cluster_python_basics_exercises Exercises python_basics_python_0220_for for Loops python_basics_python_0200_sequential_types Sequential Datatypes python_basics_python_0220_for->python_basics_python_0200_sequential_types python_basics_python_0193_while while Loops python_basics_python_0220_for->python_basics_python_0193_while python_basics_python_0160_boolean Boolean python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0110_blahblah Blahblah python_basics_python_0200_sequential_types->python_basics_python_0150_datatypes_overview python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_python_0170_if The if Statement python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0140_variables Variables python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0270_functions Functions python_basics_python_0270_functions->python_basics_python_0140_variables python_basics_python_0270_functions->python_basics_python_0150_datatypes_overview python_basics_python_0120_helloworld Hello World python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_exercises_for_primeness Exercise: Primeness (for) python_basics_exercises_for_primeness->python_basics_python_0220_for python_basics_exercises_while_primeness Exercises: Primeness (while) python_basics_exercises_for_primeness->python_basics_exercises_while_primeness python_basics_exercises_max_numbers Exercise: Determine Maximum of Two Numbers python_basics_exercises_max_numbers->python_basics_python_0140_variables python_basics_exercises_max_numbers->python_basics_python_0120_helloworld python_basics_exercises_max_numbers->python_basics_python_0150_datatypes_overview python_basics_exercises_max_numbers->python_basics_python_0170_if python_basics_exercises_max_numbers->python_basics_python_0130_syntax_etc python_basics_exercises_function_primeness Exercise: Primeness (Function) python_basics_exercises_function_primeness->python_basics_python_0270_functions python_basics_exercises_function_primeness->python_basics_exercises_for_primeness python_basics_exercises_max_numbers_function Exercise: Determine Maximum of Two Numbers (Function) python_basics_exercises_function_primeness->python_basics_exercises_max_numbers_function python_basics_exercises_while_even_numbers Exercises: Even Numbers (while) python_basics_exercises_while_even_numbers->python_basics_python_0193_while python_basics_exercises_max_numbers_function->python_basics_python_0270_functions python_basics_exercises_max_numbers_function->python_basics_exercises_max_numbers python_basics_exercises_while_primeness->python_basics_python_0193_while python_basics_exercises_while_primeness->python_basics_exercises_while_even_numbers