Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago