IniziaInizia gratis

Creating a Network of Computers

Now, you'll overload the + operator to create a Network of devices when two Computers are added. The following class has already been defined for you:

class Network:
  def __init__(self, ip_addresses):
    self.ip_addresses = ip_addresses

Here, ip_addresses is a list of IP addresses, each a string of numbers and dots.

Questo esercizio fa parte del corso

Intermediate Object-Oriented Programming in Python

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

class Computer:
  # __init__() should define operating_system and ip_address
  # as instance-level attributes
  def __init__(self, ____, ____):
    self.____ = operating_system
    self.ip_address = ____
Modifica ed esegui il codice