温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python实现打印机状态反馈

发布时间:2024-08-05 13:00:03 来源:亿速云 阅读:84 作者:小樊 栏目:编程语言
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()
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI