您好,登錄后才能下訂單哦!
class Printer:
def __init__(self, is_on=False, paper_level=100, ink_level=100):
self.is_on = is_on
self.paper_level = paper_level
self.ink_level = ink_level
def turn_on(self):
self.is_on = True
print("Printer is turned on.")
def turn_off(self):
self.is_on = False
print("Printer is turned off.")
def print_document(self, document):
if not self.is_on:
print("Printer is turned off. Cannot print document.")
return
if self.paper_level <= 0:
print("Out of paper. Cannot print document.")
return
if self.ink_level <= 0:
print("Out of ink. Cannot print document.")
return
print("Printing document:", document)
self.paper_level -= 1
self.ink_level -= 1
def check_status(self):
print(f"Printer is on: {self.is_on}")
print(f"Paper level: {self.paper_level}%")
print(f"Ink level: {self.ink_level}%")
# Usage
printer = Printer()
printer.check_status()
printer.turn_on()
printer.check_status()
printer.print_document("Sample document")
printer.check_status()
printer.print_document("Another document")
printer.turn_off()
printer.check_status()
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。