python Factoring of integers. Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 150 (which equals 2 * 3 * 5 * 5), the program should print: The factors of 150 are: 2 3 5 5

Respuesta :

Answer:

Written in Python:

num = int(input("Number: "))

i = 2

print("The factors of "+str(num)+" are ",end='')

while num > 1:

     if num%i == 0:

           num = num/i

           print(str(i)+" ",end='')

           i = 2

     else:

           i = i + 1

Explanation:

This line prompts user for input

num = int(input("Number: "))

This line initializes divisor, i to 2

i = 2

This line prints the literal in quotes

print("The factors of "+str(num)+" are ",end='')

The following while loop checks for divisor of user input and prints them accordingly

while num > 1:

     if num%i == 0:  This checks for factor

           num = num/i  Integer division

           print(str(i)+" ",end='')  This prints each factor

           i = 2  This resets the divisor back to 2

     else:

           i = i + 1

The program that asks the user for an integer and then prints out all its factors is represented as follows:

x = int(input("please input an integer: "))

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

  if x%i == 0:

     print(i)

The first line of code ask the user to input the integer number.

Then we loop through the the range of 1 to the inputted integer plus one.

The integers is then divided by the looped numbers . if it has no remainder then it is a factor.

Finally, we print the factors.

learn more about python here; https://brainly.com/question/17184408?referrer=searchResults

RELAXING NOICE
Relax