148k views
5 votes
A. Write a program that asks the user to enter an integer, then prints a list of all positive integers that divide that number evenly, excluding itself and 1, in ascending order. When you run your program, it should match the following format:

Please enter a positive integer: 12
The factors of 12 are:
2
3
4
6
b. The file must be named: factors.py
c. Code must be written in python, not C++ or Java

User Eyal Roth
by
5.5k points

1 Answer

7 votes

Answer:

Following are the program in python language the name of the program is factors.py

num= int(input("Please enter a positive integer: "))#Read the number by user

print("The factors of ",num,"are:")

for k in range(2,num): #iterating over the loop

if(num%k==0): #checking the condition

print(k)#display the factor

Output:

Please enter a positive integer: 12

The factors of 12 are:

2

3

4

6

Step-by-step explanation:

Following are the description of the program

  • Read the number by user in the "num" variable
  • Iterating the for loop from k=2 to less then "num".
  • In the for loop checking the factor of "num" variable by using % operator.
  • Finally display the factor by using print function
User TEH EMPRAH
by
6.1k points