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
-
Access the February 26, 2016, filing of the December 31, 2015, 10-K report of The Hershey Company (ticker: HSY) at SEC.gov and complete the following requirements. Required Compute or identify the...
-
Explain the three types of product costs and give an example of each.
-
(FV calculation with stated rate) You plan to put $1,000 in a savings plan and leave it there for 5 years. You can choose between various alternatives. How much will you have in 5 years under each...
-
1. What role do employee benefits play in creating and maintaining a high-performance work system? How well do you think health insurance has played that role for large companies in the United...
-
Make sure your answer is simplified and don't include any spaces or other symbols. Compute d dx (3x2 - 7x + 4 = A Question 4 (10 points) Refer to Sections 6, 7, 8, 10 Find the slope of the curve to:...
-
. With the information generated from the following table derivate from the Bureau of Economic Analysis (https://apps.bea.gov/iTable/index_nipa.cfm), please do the regression analysis, with the...
-
Create a Baby class that stores the name, rank, and number of babies of that name from the CSV file. You are also required to create any necessary methods, constructors associated with this Bab...
-
Why might the typical pyramid structure of a public accounting firm be changing? What factors might be causing the change? What are the implications of such changes for the profession?
-
A \(20^{\circ}\) pressure angle pinion with a module of 2 and 18 teeth drives a gear of 54 teeth. If the centre distance at which the gear operates is \(75 \mathrm{~mm}\), calculate the operating...
-
Why is it important that a certified public accountant fully understand the clients business and the business risks associated with specific clients?
-
The centre distance between the two shafts connected by two left-handed helical gears is \(0.4 \mathrm{~m}\). The shaft angle is \(60^{\circ}\) and normal module is \(6 \mathrm{~mm}\). The gear ratio...
-
When do we get double crank and crank-rocker mechanism?
-
Let y=tan(2x+5). Find the differential dy when x = 5 and dx = 0.4 0.8574 Find the differential dy when x = 5 and da = 0.8 1.7148
-
Suppose that a company has 10.000 outstanding shares in the beginning of the year. On April 1st, the company increases its shares by 6.000. On July 1st, the company increases its shares again, but...
-
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...
-
Lucy and Nick Lars, local golf stars, opened the Chip-Shot Driving Range on March 1 , 2005, by investing $20,000 of their cash savings in the business. A caddy shack was constructed for cash at a...
-
Today companies must compete in a global economy. Nestle, a Swiss company, is the largest food company in the world. If you were interested in broadening your investment portfolio, you might consider...
-
Natalie Koebel spent much of her childhood learning the art of cookie making from her grandmother. They passed many happy hours together, mastering every type of cookie imaginable and later devising...
Study smarter with the SolutionInn App