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...
Instructions: SLLStack (12 pts) ● Using the two properties below, implement the stack interface using the...
Instructions: SLLStack (12 pts) ● Using the two properties below, implement the stack interface using the SLLNode class from Lab 2: ○ top_node → SLLNode object or None ○ size → int, keep track of stack size ● Implement the push( ), pop( ), top( ) methods ● Use SLLNode methods: get_item( ), set_item( ), get_next( ), set_next( ) ● (5 pts) In push(item): ○ Create new SLLNode with item ○ Add new node before top node ○ Update top_node...
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 3 For this exercise you are to implement the function poly_iter in the array-backed list...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list class, which, when called with positive integer parameters a, b, c, returns an iterator over the values in the underlying list at indexes a*i2+b*i+c, for i=0, 1, 2, ... E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
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...
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...
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 2 Programming Language: Python 2 Preface: Create a new python file with a name of...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of your choosing (ex: “assignment2.py”). At the top of the file paste the following: import numpy as np import random class Base_Obstacle_Map(object):     def __init__(self, length, width):         self.map = np.zeros((length, width), dtype=np.uint8)     def add_obstacle(self, x, y):         self.map[x, y] = 1     def remove_obstacle(self, x, y):         self.map[x, y] = 0     def display_map(self):         try:             import matplotlib.pyplot as plt             plt.imshow(self.map)...
Design a function called print_area that takes two floating-point numbers, representing the length and width of...
Design a function called print_area that takes two floating-point numbers, representing the length and width of a rectangle. The print_area function calculates and prints the area of the rectangle, rounded to two decimal places. Design a function called small_enough_word that takes a string for which the number of characters will be tested, and an integer representing the maximum allowable number of characters that the word can contain. Remember: the arguments MUST be in this order (the string of text before...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT