Created
February 19, 2017 20:07
-
-
Save InquisitiveDev2016/10fb5eac964dafca78f54a9037d8f4dd to your computer and use it in GitHub Desktop.
Create a program that asks the user for a number and then prints out a list of all the divisors of that number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """1.) Understand the problem | |
| Get user input's number. | |
| print out a list of all divisors of that number | |
| 2.) Plan a solution | |
| Algorithm: | |
| - Make a new list | |
| - Get user input put it into a variable | |
| - Turn the variable into an integer | |
| - Make a range starting from the number - (number - 2), up to number - 1 | |
| - Make a for loop to iterate from the elements in the range | |
| - divide the number and the iterated elements and convert it into an integer | |
| - if the element is evenly divided by the number the user gave | |
| - Append it to the new list | |
| 3.) Carry out the plan | |
| """ | |
| new_list = [] | |
| number = int(input("Enter a number to find its divisor")) | |
| for element in range ((number - (number - 2)), (number - 1)): | |
| if number % element == 0: | |
| divide = int(number/element) | |
| new_list.append(element) | |
| print(new_list) | |
| """ 4.) Examine your results for accuracy: | |
| Input number: 24 | |
| Output: [2,3,4,6,8,12] | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment