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

Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
Create a class of DSA with two pointer objects of Employee and Customer. These objects will...
Create a class of DSA with two pointer objects of Employee and Customer. These objects will represent the head pointer of corresponding linkedlists. Add new data member functions searchCustomer & searchEmployee, to search for customers and employees separately in DSA.
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
Write two python codes for a TCP client and a server using a Socket/Server Socket. The...
Write two python codes for a TCP client and a server using a Socket/Server Socket. The client sends a file name to the server. The server checks if there is any integer value in the file content. If there is an integer number, the server will send a message to the client “Integer exists” otherwise, the message “Free of Integers”
Python Please Define a class that will represent soccer players as objects. A soccer player will...
Python Please Define a class that will represent soccer players as objects. A soccer player will have as attributes, name, age, gender, team name, play position on the field, total career goals scored. The class should have the following methods: 1. initializer method that will values of data attributes arguments. Use 0 as default for career goals scored. 2. str method to return all data attributes as combined string object. 3. addToGoals that will accept an argument of int and...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Using Python, create a function whose inputs are two matrices and whose output is the element...
Using Python, create a function whose inputs are two matrices and whose output is the element wise product of the two matrices.
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...
(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...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT