Question: Use Python: An abundant number is an integer that is less than the sum of its perfect divisors (a perfect divisor is a value that

Use Python:

An abundant number is an integer that is less than the sum of its perfect divisors (a perfect divisor is a value that divides a number evenly but is strictly less than the number itself). For example, 12 is an abundant number because its perfect divisors (1, 2, 3, 4, and 6) add up to 16. Complete the abundant() function, which takes a single positive integer value n as its argument. The function returns a Python list containing exactly the first n abundant numbers in ascending order. For example, abundant(3) would return a list with the first three abundant numbers.

Hint: You will need two loops and several helper variables to solve this problem. Your helper variables (outside the loop) should track (among other things) the number of abundant numbers seen so far as well as the integer currently being examined (which will start at 2 and increase at the end of your outer loop). The first (outer) loop should continue until you have found the required number of abundant numbers. Inside that loop, use a second loop to find and add up the perfect divisors of the number currently being examined.

Example:

Function Call Return Value
abundant(2) [12, 18]
abundant(5) [12, 18, 20, 24, 30]
abundant(10) [12, 18, 20, 24, 30, 36, 40, 42, 48, 54]

------------------

def abundant(n): # Fill in your code here for Part 1 return None # Change or replace this line 
if __name__ == "__main__": # Check the assignment itself to find what the correct output should be # for these tests. ############### Tests ############### print('Testing abundant() for 2: ' + str(abundant(2))) print('Testing abundant() for 5: ' + str(abundant(5))) print('Testing abundant() for 10: ' + str(abundant(10))) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!