In Python Create a program that asks the user for a number a

In Python,

Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don\'t remember divisor is a number that divides into another without a remainder. For example, 13 is a divisor of 26 because 26/13 has no remainder.)

Solution

n = int(input(\"Enter a number: \"))
list1 = []
for i in range(1, int(n/2)+1, +1):
if n % i == 0:
list1.append(i)
  
print list1

Output:

sh-4.3$ python main.py                                                                                                                                                                                                                                  

Enter a number: 26                                                                                                                                                                                                                                      

[1, 2, 13]                                                                                                                                                                                                                                              

sh-4.3$ python main.py                                                                                                                                                                                                                                  

Enter a number: 50                                                                                                                                                                                                                                      

[1, 2, 5, 10, 25]

In Python, Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don\'t remember divisor is a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site