def factors(n):
for i in reversed(range(1, n+1)):
if n % i ==0:
print(i)
This code currently outputs the factors of a number in a new line ex. factors(18) outputs 18 9 6 etc.... How can I make it so when I type
print("factors for 18 are:", factors(18))
Returns a list of
factors of 18: [18,9,6,3,2,1]
Without having print(i) in my function.
returnstatement?