Created
August 23, 2019 05:24
Write a python function find_smallest_number() which accepts a number n and returns the smallest number having n divisors. Handle the possible errors in the code written inside the function.
This file contains 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
''' | |
Created on 19-Aug-2019 | |
@author: Anonymous | |
''' | |
#PF-Assgn-43 | |
def find_factors(num): | |
#Accepts a number and returns the list of all the factors of a given number | |
factors = [] | |
for i in range(1,(num+1)): | |
if(num%i==0): | |
factors.append(i) | |
return factors | |
def find_smallest_number(num): | |
i=int(1) | |
while(True): | |
x=find_factors(i) | |
if(len(x)==num): | |
print(x) | |
break | |
else: | |
i=i+int(1) | |
return x[-1] | |
#start writing your code here | |
num=16 | |
print("The number of divisors :",num) | |
result=find_smallest_number(num) | |
print("The smallest number having",num," divisors:",result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment