write a program that asks the user for an integer and creates a list that consists of the factors of that integer
Answers
The following codes have been written using Python.
Once the number has been entered, we assign a list 'l' to store the factors of 'n'. To obtain the factors of 'n', we start a loop, which is an iteration statement used to perform repeated checking. We give the range as (1, n + 1) since factors start from 1 and the range function usually excludes the last value. Once it starts traversing through the range, we give a conditional statement to check if the number is a factor of 'n'. If it is, it gets store into 'l'. earlier created for the same. The final output is then printed.
Answer:
num= int(input("enter a number: "))
lst=[]
for i in range(1, num + 1):
if num % i == 0:
lst.append(i)
print(lst)
Explanation:
try this out and see it to yourself