This is a Python Program to check if two numbers are amicable numbers.
The program takes two numbers and checks if they are amicable numbers.
1. Take in both the integers and store it in separate variables.
2. Find the sum of the proper divisors of both the numbers.
3. Check if the sum of the proper divisors is equal to the opposite numbers.
4. If they are equal, they are amicable numbers.
5. Print the final result.
6. Exit.
Here is the source code of the Python Program to check if two numbers are amicable numbers. The program output is also shown below.
x=int(input('Enter number 1: ')) y=int(input('Enter number 2: ')) sum1=0 sum2=0 for i in range(1,x): if x%i==0: sum1+=i for j in range(1,y): if y%j==0: sum2+=j if(sum1==y and sum2==x): print('Amicable!') else: print('Not Amicable!')
1. User must enter both the numbers and store it in separate variables.
2. Using a for loop and an if statement, find the proper divisors of both the numbers.
3. Find the sum of the proper divisors of both the numbers.
4. The if statement is used to check if the sum of proper divisors of the number is equal to the other number and vice-versa.
5. If it is equal, both the numbers are amicable numbers.
6. The final result is printed.
Case 1: Enter number 1: 220 Enter number 2: 284 Amicable! Case 2: Enter number 1: 349 Enter number 2: 234 Not Amicable!
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Check Python Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Python Internship