Computer Science, asked by anshu3947, 1 month ago

write a program that asks the user for an integer and creates a list that consists of the factors of that integer

Answers

Answered by Equestriadash
9

The following co‎des have been written using Python.

\tt n\ =\ int(in put("Enter\ a\ number:\ "))\\l\ =\ list()\\for\ i\ in\ range(1,\ n\ +\ 1):\\{\ \ \ \ \ }if\ n\%i\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }l.append(i)\\print(l,\ "is\ the\ list\ of",\ str(n)\ +\ "'s\ factors.")

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 \tt for 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.

Answered by camarinesjealryn
1

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

Similar questions