IsNumberPrime. Python tutorials. Simple Input/Output. Algorithms. Console Application. A console application in the Python programming language. The program does the following:
- Asks the user to enter a positive integer.
- Creates a variable to count the number of divisors of the number with the value 0.
- The message displayed is: "The number has the following divisors:"
- The loop with the parameter is executed: 4.1. The initial value of the parameter is set to 1, and the final value is set to the number entered from the keyboard. 4.2. A series of loops is executed, where the remainder from dividing the number entered from the keyboard by the loop variable-parameter is calculated. 4.3. If the remainder is zero, the value of the loop parameter is displayed on the screen. The value of the variable for the number of divisors is incremented by 1. 4.4. The value of the loop parameter is compared with the final value. If it is less, the loop is executed. Otherwise, it terminates. 4.5. The loop parameter variable is incremented by the loop increment. In this example, it is 1.
- The number of divisors of a number determines its type: 0 or 1 - neither prime nor composite. 2 - prime. Greater than 2 - composite. The corresponding messages are displayed on the screen. Developed in the Spyder integrated environment (in the Microsoft Visual Studio Code editor).
IsNumberPrime. Занятия по Python. Простой ввод-вывод. Алгоритмы. Консольное приложение. Консольное приложение написанное на языке программирования Python. Программа делает следующее:
- Просит пользователя ввести целое положительное число.
- Содаёт переменную для подсчёта количества делителей числа со значением 0.
- Выводится сообщение:"Число имеет следующие делители:"
- Выполняется цикл с параметром: 4.1. Начальное значение параметра уставливается равным 1, а конечное - числу, введённому с клавиатуры. 4.2. Выполняется серия цикла, где вычисляется остаток от деления числа, введённого с клавиатуры на переменную-параметр цикла. 4.3. Если остаток равен нулю, то значение параметра цикла выводится на экран. Значение переменной количества делителей числа увеличивается на 1. 4.4. Значение параметра цикла сравнивается с конечным. Если оно меньше цикл выполняется. В противном случае - завершается. 4.5. Переменная параметра цикла увеличивается на шаг цикла. В данном примере он равен 1.
- По количеству делителей числа определяет его тип: 0 или 1 - ни простое ни составное. 2 - простое. Больше 2 - составное. Соответствующие сообщения выводятся на экран. Разработано в интегрированной среде Spyder (в редакторе Microsoft Visual Studio Code).