Question

In: Computer Science

In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside...

In python please

Problem

Create two server objects using the class

create a function, biggest_server_object_sum, outside of the ServerClass class, that:

1. Takes the IP

2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128)

3. Returns the Server object with the larger sum

Example:

server_one = ServerClass("127.0.0.1")

server_two = ServerClass("192.168.0.1")

result = biggest_ip_sum(server_one, server_two)

print(result)

Hint

Modify get_server_ip in the previous problem.

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

Please use this code to start 

class ServerClass:
    """ Server class for representing and manipulating servers. """

    def __init__(self, server_ip):
        """ Create a ServerClass with a server_ip instantiated"""
        self.server_ip = server_ip


# TODO - biggest_server_object_sum
def biggest_server_object_sum(server_one, server_two):
    return

Solutions

Expert Solution

class ServerClass:

    """ Server class for representing and manipulating servers. """

    def __init__(self, server_ip):

        """ Create a ServerClass with a server_ip instantiated"""

        self.server_ip = server_ip


# TODO - biggest_server_object_sum

def biggest_server_object_sum(server_one, server_two):

    # compute sums of octets of first server

    ip = server_one.server_ip

    ip = ip.split('.')

    sum1 = int(ip[0])+int(ip[1])+int(ip[2])+int(ip[3])

    # compute sums of octets of second server

    ip = server_two.server_ip

    ip = ip.split('.')

    sum2 = int(ip[0])+int(ip[1])+int(ip[2])+int(ip[3])

    # return server object with largest sum

    if sum1 > sum2:

        return server_one

    return server_two


# testing code

server_one = ServerClass("127.0.0.1")

server_two = ServerClass("192.168.0.1")

result = biggest_server_object_sum(server_one, server_two)

print(result.server_ip)

.

Screenshot:

Output:

.


Related Solutions

How to create a FTP server using python and TCP Ports How to create a FTP...
How to create a FTP server using python and TCP Ports How to create a FTP server using python and UDP Ports
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list...
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list with the named elements ‘name’, ‘subjects completed’, ‘grades’, and ‘credit’. Write a studentRecord method for the generic function mean, which returns a weighted GPA, with subjects weighted by credit. Also write a studentRecord method for print, which employs some nice formatting, perhaps arranging subjects by year code. Finally create a further class for a cohort of students, and write methods for mean and print...
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play....
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play. This will include, at least, the game board, the two types of pieces and the two sides. You will need to determine the best way to represent the relationship between them. 2) Set up one side of the board. Print the status of the board.
This is using Python, it is utilizing code from a Fraction class to create a Binary...
This is using Python, it is utilizing code from a Fraction class to create a Binary Class Please leave comments so I may be able to learn from this. Instruction for Binary Class: Exercise 6.18: Design an immutable class BinaryNumber, in the style of our Fraction class. Internally, your only instance variable should be a text string that represents the binary value, of the form '1110100'. Implement a constructor that takes a string parameter that specifies the original binary value....
(32%) Create a class of function objects called StartsWith that satisfies the following specification: when initialized...
(32%) Create a class of function objects called StartsWith that satisfies the following specification: when initialized with character c, an object of this class behaves as a unary predicate that determines if its string argument starts with c. For example, StartsWith(’a’) is a function object that can be used as a unary predicate to determine if a string starts with an a. So StartsWith(’a’)("alice") would return true but StartsWith(’a’)("bob") would return false. The function objects should return false when called...
In python i want to create a function. The function will take in two linked lists...
In python i want to create a function. The function will take in two linked lists as the parameters. If one is shorter than the other then the shorter will be the length. I want to take the values from both linked lists and turn them into tuples. I then want these tuples to be put into a new linked list. I want to return that linked list. I want to do this using recursion and no helper functions or...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
PYTHON: This is the posted problem: General Instructions Create a function called DeterminePrice that will determine...
PYTHON: This is the posted problem: General Instructions Create a function called DeterminePrice that will determine the cost of purchased software. The price is of the software is $350 per license. However, when purchased in larger quantities a discount is given. For quantites less than 10 copies, there is no discount. For quantities greater than 10 and less than and including 20, a 10% discount is given. For quantities greater than 20 and less than and including 30, a discount...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT