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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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." ) |