Write a program in python, to print divisor of a given number
Steps:
- Ask User to enter a Number
- Use for loop over 1 to 100 to check divisor
- use if loop to find the correct 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
#method one | |
# divisor of number | |
num=int(input("Enter a number between 1 to 100 : Print divisor of number :")) | |
for i in range(1,101): | |
if(num%i==0): | |
print(i,"is divisor of number ",num) | |
Enter a number between 1 to 100 : Print divisor of number :96 1 is divisor of number 96 2 is divisor of number 96 3 is divisor of number 96 4 is divisor of number 96 6 is divisor of number 96 8 is divisor of number 96 12 is divisor of number 96 16 is divisor of number 96 24 is divisor of number 96 32 is divisor of number 96 48 is divisor of number 96 96 is divisor of number 96Second Method
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
#Method 2 | |
__author__="Simualtion-hub" | |
num=int(input("Enter a number between 1 to 100 : Print divisor of number:")) | |
ListOfDivisor=[] | |
for i in range(1,101): | |
if (num%i==0): | |
ListOfDivisor.append(i) | |
#printing list | |
print("The number has following divisors :",ListOfDivisor) | |
Enter a number between 1 to 100 : Print divisor of number:96 The number has following divisors:[1, 2, 3, 4, 6, 8, 12,16, 24, 32, 48, 96]
0 Comments
If you have any doubt and suggestion Please let me know