Practice Python Exercise 4

  • #### 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 know what a divisor is, it is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.)

In [4]:
def main():
    while True:
        try:
            num = int(input("Enter a number \n"))
            divisors = [i for i in range(1,num+1) if num % i  == 0]
            print("Divisors of {} is {}".format(num,divisors))
            break
        except ValueError:
            print("Very Funny Kid, Now gimme a number !")
main()


Enter a number 
Hello
Very Funny Kid, Now gimme a number !
Enter a number 
5
Divisors of 5 is [1, 5]

In [ ]: