Bắt đầu ngayBắt đầu miễn phí

Kế thừa từ lớp Computer

Trong bài tập này, bạn sẽ luyện tập kế thừa bằng cách tạo một lớp tên là Tablet. Bên dưới là lớp Computer, đã được định nghĩa sẵn để bạn sử dụng trong các bước tiếp theo.

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

Bài tập này là một phần của khóa học

Lập trình Hướng đối tượng Nâng cao với Python

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

class Tablet(Computer):
  pass

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

# Update my_tablet's software to version 1.1.2
my_tablet.____("____")
print(my_tablet.____)
Chỉnh sửa và Chạy Mã