Question

Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two...

Python

Problem 1

Create a function, biggest_ip_sum, outside of the ServerClass class, that:

1. Takes two ServerClass objects

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

3. Returns the larger number

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)

In the example above, result will be 361.

_________________________________

Problem 1 Here is the code to start with

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 - Write biggest_ip_sum function
def biggest_ip_sum():
    return

____________________________________

Problem 2

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.

__________________________

Problem 2 Here is the code to start with

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

______________________________

Problem 3

Create a variable, server_name, and assign a value to it inside `ServerClass` .

_____________________________

Problem 3 Here is the code to start with

class ServerClass:
    """ Server class for representing and manipulating servers. """
    # TODO - Add server_name variable


    def get_server_name(self):
        return self.server_name

Homework Answers

Answer #1

Have a look at the below code. I have put comments wherever required for better understanding.

Problem 1 and 2 are quite similar. So I have explained problem 1.

Problem 1 & 2...

Problem 3...

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 - Write biggest_ip_sum function
def biggest_ip_sum(server_one,server_two):
  # split the ip adrress by . literal
  one = server_one.server_ip.split(".") 
  two = server_two.server_ip.split(".")
  # create variables to store sum 
  sum_one,sum_two = 0,0 
  # loop in through the first ip address to sum
  for i in one:
    sum_one+=int(i)
  # loop in through the second ip address to sum
  for j in two:
    sum_two+=int(j) 
  # return greater sum
  return sum_one if sum_one>sum_two else sum_two


server_one = ServerClass("127.0.0.1")
server_two = ServerClass("192.168.0.1")
result = biggest_ip_sum(server_one, server_two)
print(result)


class ServerClass:
    """ Server class for representing and manipulating servers. """
    # TODO - Add server_name variable

    def __init__(self):
      # This is the server name variable
      self.server_name = "XYZ"


    def get_server_name(self):
        return self.server_name

Happy Learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In python Please Problem We want to create a DHCP service that assigns a random, unique...
In python Please Problem We want to create a DHCP service that assigns a random, unique IP with subnet mask 255.0.0.0. This means the service only sets the last 3 octets of an IP. For example if the dhcp_service function is called by an IP of "192.0.0.0", it should keep the 192 and change the rest: 1. Create a dhcp_service(ip_address) function, outside of the ServerClass 2. Have request_dhcp_ip call the dhcp_service and set the ServerClass object's IP to the generated...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
Python #Imagine you're writing a program to check if a person is #available at a certain...
Python #Imagine you're writing a program to check if a person is #available at a certain time. # #To do this, you want to write a function called #check_availability. check_availability will have two #parameters: a list of instances of the Meeting class, and #proposed_time, a particular date and time. # #check_availability should return True (meaning the person #is available) if there are no instances of Meeting that #conflict with the proposed_time. In other words, it should #return False if proposed_time...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a blue vote, a red vote, or a purple. This information is stored in the "value" attribute. The function Poll returns a list of random votes. In the code below, some_poll is a list of 32 random votes. some_poll = Poll(32) # ----------------------------------------------------- import random # ----------------------------------------------------- # # Return a list of n random votes # # ----------------------------------------------------- def Poll(n=16): # # A random...
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT