定义一个列表名为price,方法1:使用循环完成 方法2:使用列表推导式完成。

定义一个列表名为price,存储的是你打算618期间购买的5种物品的价格。如果618期间这些产品都打5.5折,那么打印出这几种物品打折后的价格(保留小数点后2位)。
方法1:使用循环完成
方法2:使用列表推导式完成。

求帮助!


def run():
    price = [99.8, 998, 243.5, 9.8, 19.9]
    # 方法1
    for i in price:
        print(round(i * 0.55, 2))

    # 方法2
    discount_price = [round(i * 0.55, 2) for i in price]
    print(discount_price)
    pass
run()

结果:

img