Computer Science, asked by sandhhyaupa, 29 days ago

write a program to input two numbers (say a and b) and check whether they are amicable numbers or not .If the sum of factors of a excluding a itself is equal to b and the sum of factors of b excluding b itself is equal to a then they are said to amicable numbers​

Answers

Answered by MisterIncredible
1

ANSWER

Required to find :-

  • Whether given numbers are amicable or not ?

Constraints : -

  • Input only 2 values

What are Amicable number ?

Consider 2 numbers namely x & y .

suppose x has 5 factors and

sum of the factors of x = y

Similarly,

If y has some 3 factors and

sum of the factors of y = x

If both conditions are satisfied then the given numbers are called as Amicable numbers

Program :-

#Taking input from the users

value_1 = int(input( " >>> "))

value_2 = int(input(" >>> "))

#defining a function to list of the factors for a given number

''' How this function woks ?

The below function takes one value as an argument and return it's factors in the form of an list

'''

def amicable(x):

value = x

list_vals = []

i = 1

while True:

if i == 1000000 or i == value:

break

elif value % i !=0:

pàss

else:

list_vals.append(i)

i+= 1

return list_vals

#one more function to find the sum of factors

def sum(list):

sum = 0

for i in list:

sum+= i

return sum

#checking for the condition of amicable numbers

list_val_of_1 = amicable(value_1)

result_of_val_1 = sum(list_val_of_1)

list_val_of_2 = amicable(value_2)

result_of_val_2 = sum(list_val_of_2)

if result_of_val_1 == value_2 and result_of_val_2 == value_1:

print("Yes! they are amicable numbers ")

else:

print("Ops! this pair doesn't belongs to amicable numbers ")

Output :

refer to the attachment !

Note : -

If the program is showing any other error rather than indentàtion error then kindly change the letter à word pàss to a in the above côde inorder to avoid errors due to the fancy char-acter à .

Attachments:
Similar questions