不确定为什么脚本运行但不给出输出?

问题描述 投票:0回答:2

我是Python的新手,我对Python的基础知识有一定的了解。我试图通过遵循教程来学习 OOP 细节,然后当我在 VScode 上运行我的代码时我意识到了。它没有给我任何回报。我只是返回文件路径。我不知道该怎么办。我尝试添加打印以查看是否有任何结果,但没有!

class Item:
    pay_rate = 0.8
    def __init__(self, name: str, price: float, quantity=0):
        assert price >= 0, f"Price {price} should be greater or equal to zero!"
        assert quantity >= 0, f"Quantity {quantity} should be greater or equal to zero!"


        self.name = name
        self.price = price
        self.quantity = quantity

    def calculate_total_price(self):
        return self.price * self.quantity

    def apply_discount(self):
        self.price = self.price * self.pay_rate

    
item1 = Item("Phone", 100, 1)
item2 = Item("Laptop", 1000, 3)
item3 = Item("Cable", 10, 5)
item4 = Item("Mouse", 50, 5)
item5 = Item("Keyboard", 75, 5)

在此输入图片描述

嗯,看起来就是这个样子

python class
2个回答
0
投票

这意味着程序没有向控制台输出任何内容,因为您运行代码并只能看到文件路径,因此您应该仔细检查代码是否有任何错误以及其他显示结果的方法


0
投票

明白了伙计们!这是一个翻译问题!

© www.soinside.com 2019 - 2024. All rights reserved.