201k views
2 votes
Write a program that will take a user-input number and then display all of the whole # factors for that number. For example, if I typed in 4, your program should display all # of the factors for 4 (1, 2, and 4). Your program should work for any number. # # Hint: What approach would you take if faced with this scenario? What Python operator can # be used to determine whether a number is divisible by another number?

User Locket
by
5.0k points

1 Answer

0 votes

Answer:

The program to this question can be given as:

Program:

Number=int(input("Insert a number :")) # input a number from

fact=[] # crate list

for k in range(1,Number+1): #loop

if Number%k==0: # check number is divisible by k

fact.append(k)

print ("Factors of {} = {}".format(Number,fact)) #print value

Output:

Enter a number: 4

Factors of 4= [1,2,4]

Explanation:

In the above python program firstly we declare a variable that is Number in this variable we take user input. To user input, we first convert the value into the integer and the input function is used for input. Then we declare a list that fact =[]. In the python, the list is used for placing all the elements inside a square bracket [ ] all the elements will be separated by commas. Then we use for loop it is used for iterate over a sequence. Then we use the if statement. It is used for check condition. In this statement, the number is divided by k. if the remainder is equal to 0. It will print the value.

User Pamcevoy
by
4.7k points