Perfect number means, the sum of the divisors or factors of a positive integer n, excluding...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Perfect number means, the sum of the divisors or factors of a positive integer n, excluding n itself. If the sum is equal to n then it is a perfect number. Consider the following examples for the perfect numbers. Example: i. ii. n=9 divisors of n are: 1, 3 sum of the divisors is=1+3=4 In this case sum of the divisors is not equal to n, so n is not a perfect number. n=6 divisors of 'n are: 1,2,3 sum of the divisors is: 1+2+3=6 In this case sum of the divisors is equal to n, so n is a perfect number. Problem: Create two lists with the names xlist and ylist. Append xlist with 100 random numbers between 1 and 30 then copy all the perfect numbers from xlist to the ylist. Display the contents of xlist and ylist. It should consist of the following functions: def generateData (xlist): Appends xlist with 100 random numbers between 1 and 30. def fill_ylist (xlist, ylist): This function will pass each element of xlist to a sub function perfect Number(). If it is a perfect number then add it to ylist dynamically. def perfect Number (): Each element will be received as a number to determine whether the number is perfect. It will return True, if the number is pefect. def printOutput(): If the list is not empty, then print the list as formatted in the sample output below otherwise display "There are no elements in the list" def main (): In main (), lists are declared and functions generateData (), fill_ylist(), and printOutput() are called. Sample Output: Randoe Numbers from xlist[] = 27 10 27 9 9 10 14 12 5 22 23 29 3 7 28 12 2 20 28 9 21 24 29 22 1 3 24 7 22 17 29 27 11 6 11 23 13 25 7 10 15 17 18 16 21 5 12 12 20 19 13 5 3 23 20 27 9 18 17 17 24 21 13 4 14 4 22 1 21 8 25 13 11 16 4 4 28 7 15 3 22 23 20 23 2 25 16 7 18 21 16 22 23 14 29 25 13 4 25 Perfect numbers from ylist are: 28 28 6 28 Randon Numbers from xlist[] = 7 17 10 26 22 9 20 21 21 22 8 26 17 24 12 16 25 24 11 9 14 19 13 21 17 12 7 24 18 20 22 20 24 23 18 23 18 15 17 19 12 16 22 14 26 25 24 15 13 18 16 8 25 11 22 26 17 17 25 26 22 21 23 14 20 8 7 12 16 9 12 9 25 11 25 12 7 19 10 26 19 20 13 14 19 15 13 15 18 23 19 10 24 19 25 19 9 22 21 18 Perfect numbers from ylist are: No elements in the list Perfect number means, the sum of the divisors or factors of a positive integer n, excluding n itself. If the sum is equal to n then it is a perfect number. Consider the following examples for the perfect numbers. Example: i. ii. n=9 divisors of n are: 1, 3 sum of the divisors is=1+3=4 In this case sum of the divisors is not equal to n, so n is not a perfect number. n=6 divisors of 'n are: 1,2,3 sum of the divisors is: 1+2+3=6 In this case sum of the divisors is equal to n, so n is a perfect number. Problem: Create two lists with the names xlist and ylist. Append xlist with 100 random numbers between 1 and 30 then copy all the perfect numbers from xlist to the ylist. Display the contents of xlist and ylist. It should consist of the following functions: def generateData (xlist): Appends xlist with 100 random numbers between 1 and 30. def fill_ylist (xlist, ylist): This function will pass each element of xlist to a sub function perfect Number(). If it is a perfect number then add it to ylist dynamically. def perfect Number (): Each element will be received as a number to determine whether the number is perfect. It will return True, if the number is pefect. def printOutput(): If the list is not empty, then print the list as formatted in the sample output below otherwise display "There are no elements in the list" def main (): In main (), lists are declared and functions generateData (), fill_ylist(), and printOutput() are called. Sample Output: Randoe Numbers from xlist[] = 27 10 27 9 9 10 14 12 5 22 23 29 3 7 28 12 2 20 28 9 21 24 29 22 1 3 24 7 22 17 29 27 11 6 11 23 13 25 7 10 15 17 18 16 21 5 12 12 20 19 13 5 3 23 20 27 9 18 17 17 24 21 13 4 14 4 22 1 21 8 25 13 11 16 4 4 28 7 15 3 22 23 20 23 2 25 16 7 18 21 16 22 23 14 29 25 13 4 25 Perfect numbers from ylist are: 28 28 6 28 Randon Numbers from xlist[] = 7 17 10 26 22 9 20 21 21 22 8 26 17 24 12 16 25 24 11 9 14 19 13 21 17 12 7 24 18 20 22 20 24 23 18 23 18 15 17 19 12 16 22 14 26 25 24 15 13 18 16 8 25 11 22 26 17 17 25 26 22 21 23 14 20 8 7 12 16 9 12 9 25 11 25 12 7 19 10 26 19 20 13 14 19 15 13 15 18 23 19 10 24 19 25 19 9 22 21 18 Perfect numbers from ylist are: No elements in the list
Expert Answer:
Answer rating: 100% (QA)
import random def generateDataxlist Function that generates 100 random integers between 1 30 for i i... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Stan, a trained and licensed plumber, carelessly installed a steam heater in George's restaurant, and, as a result, George was seriously burned when a heater pipe exploded. Sylvie, a qualified...
-
You have just been hired as an analyst to assist the manager of Heartbreak Hotel Your first assignment is to examine and report on the reservations policy in the hotel. Heartbreak Hotel routinely...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-4. Ivan and Irene paid the following in 2012 (all by check or can otherwise be...
-
All administrative laws are criminal laws and enforceable as such even though they are not part of the Criminal Code. True False
-
(a) Show that, by setting r=R+y in the right-hand member of Eq. (13.17) and expanding that member in a power series iny/R, the expression in Eq. (13.16) for the potential energy Vg due to gravity is...
-
On January 1, 20X1, Brooks Energy issued $200 million of 15-year, floating rate debentures at par value. The debentures pay interest on June 30 and December 31 of each year. The floating interest...
-
It is said that "the higher the MARR, the higher the price that a company should be willing to pay for equipment that reduces annual operating expenses." Explain the reasoning behind this statement.
-
Breakeven point, what-if analysis Premier Products, Inc., is considering replacing its existing machine with a new and faster machine that will produce a more reliable product and will turn around...
-
What is the value of a project that generates a cash flow of $50,000 in the first month, with the cash flows growing at 0.35% per month forever? The interest rate is 10.8%.
-
Troys Tires sells a certain brand tire which has a daily demand that is normally distributed, with a mean of 15 tires and a standard deviation of 4 tires. (In your model use integers for all...
-
A company uses the retail method to estimate inventories. The following information is for the first six months of the current year: beginning inventory at cost and retail were $70,000 and $100,000...
-
A pressure vessel of 250-mm inner diameter and 6-mm wall thickness is fabricated from a 1.2- m section of spirally welded pipe AB and is equipped with two rigid end plates. The gage pressure inside...
-
The preliminary survey results just came back on the specialty catalog project, and they look great! The average planned order size was $42.33, well above the $15 that was hoped for. The group leader...
-
2) An opening bridge takes 60 seconds to open. The opening motion is shown on the angular velocity time diagram (Figure 14). Figure 14 Angular Velocity (rad.s) 0.03 0.02 0.01 0 10 20 30 40 40 50 60...
-
What is the meaning of all of these? "Transforming the complex to the simple is pure genius" "Complexity that works is built up out of modules that work perfectly, layered one over the other"
-
Why do we employ perceptual screens to filter the ads to which we are exposed? 2. What does the term consumer behavior refer to, and why is it important to advertisers? What is the difference...
-
Complete and balance each of the following equations. If no reaction occurs, write NOREACTION. Express your answer as a chemical equation. Identify all of the phases in your answer. 1) KCl (aq) + CaS...
-
What are the two components of a company's income tax provision? What does each component represent about a company's income tax provision?
-
The area of a hexagon can be computed using the following formula (s is the length of a side): Write a program that prompts the user to enter the side of a hexagon and displays its area. Here is a...
-
Implement the preorder method in BST using a stack instead of recursion. Write a test program that prompts the user to enter 10 integers, stores them in a BST, and invokes the preorder method to...
-
Revise Listing 8.3, FindNearestPoints.java, to display all closest pairs of points with the same minimum distance. Here is a sample run: Listing Enter the number of points: 8-Enter Enter 8 points: 0...
-
Journalize the transactions of Luna Technology Solutions. Include an explanation with each journal entry. Use the following accounts: Cash; Accounts Receivable; Supplies; Prepaid Advertising; Land;...
-
As the manager of Yum Yum Thai, you must deal with a variety of business transactions. Provide an explanation for the following transactions: a. Debit Equipment and credit Cash. b. Debit Saelim,...
-
Schuster Services reported assets of $800 and equity of $480. What is Schuster Services debt ratio? a. 60% b. 40% c. 67% d. Not enough information is provided.
Study smarter with the SolutionInn App