Jul-22-2018, 11:38 PM
(This post was last modified: Jul-22-2018, 11:39 PM by TitaniumGene.)
I wrote this code after taking a few basic Python courses. I welcome feedback on how to improve it.
print("This program will list the factors of a number for you.") #Need a function to find factors of an integer. def find_factors(integer): factors = [] #It has to be 1 more than the integer to include the actual integer. for i in range(1, integer + 1): if integer % i == 0: factors.append(i) return print("The factors of",integer,"are",factors,".") #Check the input for valid. while True: product = input("Enter a positive integer: ") if product.isalpha() == True: print("That is not an integer.") elif product.isdigit() == True: print("That is a valid response.") product = int(product) #Converts the product string into an integer. find_factors(product) break else: print("Try again.")