繁体   English   中英

我有一个包含一些项目及其定价的代码,我应该打印出低于特定价格的单词

[英]I have a code that has some items and its pricings, i am supposed to print out the words that is below certain price

price = {"table": 120, "chair": 40, "lamp": 14, "bed":250, "mattress": 100, "pillow": 10, "shelf": 70, "sofa": 400}

我试过像

if price <= 100:
    print(price)

您需要一个for循环来检查if条件然后打印。

prices = {"table": 120, "chair": 40, "lamp": 14, "bed":250, "mattress": 100, "pillow": 10, "shelf": 70, "sofa": 400}


for thing in prices:
    if prices[thing] <= 100:
        print(thing, prices[thing])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM