107k views
1 vote
write a program that asks the user to enter a positive integer, then prints a list of all positive integers that divide that number evenly, including 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: 1 2 3 4 6 12 the file must be named: factors.py

1 Answer

2 votes

Answer:

The program is written using python

See explanation section for detailed explanation; as the program does not accommodate comments.

Program starts here

num = int(input("please enter a positive integer: "))

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

for i in range(1, num + 1):

if num % i == 0:

print(i)

Step-by-step explanation:

This line prompts the user for input

num = int(input("please enter a positive integer: "))

This line prints a string literal which states the factors of the input number

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

The next line is a for statement that iterates all positive numbers from 1 till the inputted number

for i in range(1, num + 1):

This next line checks for the factors of the user input by checking for remainders.

if num % i == 0:

Lastly, the factors are printed

print(i)

User Kevin Richardson
by
5.2k points