CommencerCommencer gratuitement

Inheriting a Computer class

In this exercise, you'll practice inheritance by creating a class called Tablet. Below is the Computer class, which has been defined for you to use in the following steps.

class Computer:
  def __init__(self, software_version):
    self.software_version = software_version

  def install_app(self, app_name, app_store):
    if app_store:
      print(f"Installing {app_name} from App Store.")
    else:
      print(f"Installing {app_name} from other provider.")

  def update_software(self, new_software_version):
      self.software_version = new_software_version

Cet exercice fait partie du cours

Intermediate Object-Oriented Programming in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

class Tablet(Computer):
  pass

# Create the my_tablet instance
____ = ____("____")

# Update my_tablet's software to version 1.1.2
my_tablet.____("____")
print(my_tablet.____)
Modifier et exécuter le code