In: Computer Science
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
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:
.