1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
10

Write the Number class that can be used to test if the number is odd, even, and perfect. A perfect number is any number that is

equal to the sum of its divisors. Write the NumberAnalyzer class that has an ArrayList of Number to determine how many numbers in the list are odd, even, and perfect.
Computers and Technology
1 answer:
egoroff_w [7]3 years ago
6 0

Answer:

Explanation:

The following code is written in Python. It creates a class that takes in one ArrayList parameter and loops through it and calls two functions that check if the numbers are Perfect, Odd, or Even. Then it goes counting each and printing the final results to the screen.

class NumberAnalyzer:

   def __init__(self, myArray):

       perfect = 0

       odd = 0

       even = 0

       for element in myArray:

           if self.isPerfect(element) == True:

               perfect += 1

           else:

               if self.isEven(element) == True:

                   even += 1

               else:

                   odd += 1

       print("# of Perfect elements: " + str(perfect))

       print("# of Even elements: " + str(even))

       print("# of Odd elements: " + str(odd))

   def isPerfect(self, number):

       sum = 1

       i = 2

       while i * i <= number:

           if number % i == 0:

               sum = sum + i + number / i

           i += 1

       if number == sum:

           return True

       else:

           return False

   def isEven(self, number):

       if (number % 2) == 0:

           return True

       else:

           return False

You might be interested in
Alan wants to buy camera support equipment that would provide mechanical support to his camera and which could also store extra
Andru [333]

Answer:

Could it be tripod?

Explanation:

If you did this question do you remember what the answer was?

4 0
3 years ago
Please answer........
Vitek1552 [10]

Using the try-except statement, the fix is as follows:

while True:

   try:

       boxes = int(input("How many boxes do you have?"))

       sweaters = int(input("How many sweaters do you have?"))

       break

   except:

       print("Input invalid")

sweatersPerBox = sweaters/boxes

print("You need to put",sweatersPerBox,"sweaters in each box")

<h3>How to prevent the program from crashing?</h3>

The program is given as:

boxes = int(input("How many boxes do you have?"))

sweaters = int(input("How many sweaters do you have?"))

sweatersPerBox = sweaters/boxes

print("You need to put",sweatersPerBox,"sweaters in each box")

The above program would crash when the user enters string inputs.

Examples of string inputs are "7h", "bh"...

One way to fix the error is the use of the try-except statement.

Using the try-except statement, the fix is as follows:

while True:

   try:

       boxes = int(input("How many boxes do you have?"))

       sweaters = int(input("How many sweaters do you have?"))

       break

   except:

       print("Input invalid")

sweatersPerBox = sweaters/boxes

print("You need to put",sweatersPerBox,"sweaters in each box")

The above program would continue running until the user enters a valid input

Another way is to end the program when the user enters string inputs

Read more about python programs at:

brainly.com/question/26497128

#SPJ1

7 0
2 years ago
Display all the natural numbers from 1 to 100 that are exactly divisible by 3 and 7 using FOR … NEXT. Without using Mod
Tcecarenko [31]

Answer:

FOR i% = 1 TO 100

 IF ((i%\3) = i%/3) AND ((i%\7) = i%/7)  THEN

   PRINT i%

 END IF

NEXT i%

Explanation:

Of course using MOD would be cleaner, but another way to check if a number is integer divisable is to compare the outcome of an integer division to the outcome of a floating-point division. If they are equal, the division is an integer division.

The program outputs:

21

42

63

84

6 0
3 years ago
Which search engine optimization technique involves sending data describing your web site to the search engines and then paying
vazorg [7]

Answer:

Search feeds.

Explanation:

Search feeds seem to be the search engine optimization strategy includes transmitting information to those of the search engines that explaining the user's website and afterward charging the fee to assure that is pages would be included in the site engine listing.

So, the following answer is correct according to the given scenario.

8 0
3 years ago
The need to upgrade which component would likely lead to replacing the computer?
Alex787 [66]

Answer:

CPU

Explanation:

The CPU is essentially the brain of a CAD system soooo

6 0
3 years ago
Other questions:
  • whats something that u want to do but ur parents wont allow it like having a phone or going to a college ​
    11·2 answers
  • You are the system administrator for a medium-sized Active Directory domain. Currently, the environment supports many different
    7·1 answer
  • Which quality of service (QoS) mechanism provided by the network does real-time transport protocol (RTP) rely on to guarantee a
    13·1 answer
  • Which of the following is NOT a good idea to do after you change the root password?
    12·1 answer
  • Give 5 uses of software and hardware.
    15·1 answer
  • Explain the working principle of computer? can anyone tell​
    14·1 answer
  • Susan uploads her newly created files on the web server using FTP. What should she ensure while uploading to prevent other users
    9·2 answers
  • What are the values of a[k] and a[k+1] after code corresponding to the following pseudocode runs?
    9·2 answers
  • Which types of file formats are the best choice for files that may need to be edited later?
    14·1 answer
  • Select the correct answer.<br><br> Which statement is true with respect to Java?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!