Jul-16-2019, 02:02 AM
My problem asks me to write a program to find all the divisors of a number. What I have done so far I realize is of target from that goal however there is part of this code that does not act as I want.
Inline 18 I have an if statement that is supposed to put x into a list if the check inline 17 is equal to 0. However, it only does that only 1 time after which the if statement lets through any number into the list decreasing by 1.
Inline 18 I have an if statement that is supposed to put x into a list if the check inline 17 is equal to 0. However, it only does that only 1 time after which the if statement lets through any number into the list decreasing by 1.
number = int(input("Enter a number for which you want to know all the divisors ")) divisors = [] i = number list = range(0, (number + 1)) check = list[number] % 2 if check != 0: print(str(number) + " does not have any divisors") else: while i > 0: print("The list char") print(list[i]) print("The i char") print(i) x = list[i] / 2 print("The x value") print(x) check = list[i] % 2 if check == 0: divisors.append(x) i -= 1 print("The divisors of " + str(number) + " are: " + str(divisors))