Embed presentation
Download to read offline
![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]](https://image.slidesharecdn.com/inpythoncreateaprogramthataskstheuserforanumberandthe-230903213328-59d05c7f/75/In-Python-Create-a-program-that-asks-the-user-for-a-number-and-the-pdf-1-2048.jpg)
The document describes a Python program that prompts the user for a number and outputs a list of its divisors. It explains that divisors are numbers that divide another without a remainder. An example of the program's output is provided, showing divisors for the numbers 26 and 50.
![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]](https://image.slidesharecdn.com/inpythoncreateaprogramthataskstheuserforanumberandthe-230903213328-59d05c7f/75/In-Python-Create-a-program-that-asks-the-user-for-a-number-and-the-pdf-1-2048.jpg)