Exercise: Primeness (while)

Write a program that checks whether a given number is prime!

The number that the program checks can be given in two ways,

  • As a commandline parameter (for non-interactive use)

  • Prompted from the user, using the input() function

Note

A number is prime, if …

  • It is not equal to 1

  • It is only divisible by 1 and itself

$ python prime.py 7
prime
$ python prime.py 6
not prime
$ python prime.py 1
not prime
$ python prime.py 2
prime

Dependencies

cluster_python Python Programming cluster_python_exercises Exercises cluster_python_exercises_legacy Exercises (Legacy) cluster_python_basics Python: The Language Fundamentals python_exercises_legacy_while_primeness Exercise: Primeness (while) python_exercises_legacy_cmdline_digit Exercise: Digit to English Word python_exercises_legacy_while_primeness->python_exercises_legacy_cmdline_digit python_basics_python_0193_while while Loops python_exercises_legacy_while_primeness->python_basics_python_0193_while python_basics_python_0139_commandline_argv Commandline Arguments (sys.argv) python_exercises_legacy_while_primeness->python_basics_python_0139_commandline_argv python_basics_python_0150_datatypes_overview_compound Compound Datatypes python_exercises_legacy_cmdline_digit->python_basics_python_0150_datatypes_overview_compound python_basics_python_0120_helloworld Hello World python_exercises_legacy_cmdline_digit->python_basics_python_0120_helloworld python_basics_python_0150_datatypes_overview Datatypes python_exercises_legacy_cmdline_digit->python_basics_python_0150_datatypes_overview python_exercises_legacy_cmdline_digit->python_basics_python_0139_commandline_argv python_basics_python_0160_boolean Boolean python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0170_if The if Statement python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0110_blahblah Blahblah python_basics_python_0125_running Running Python Programs python_basics_python_0125_running->python_basics_python_0120_helloworld python_basics_python_0150_datatypes_overview_compound->python_basics_python_0150_datatypes_overview python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0140_variables Variables python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0139_commandline_argv->python_basics_python_0130_syntax_etc python_basics_python_0139_commandline_argv->python_basics_python_0125_running