打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
8.20二 二

一.字典里有列表。

# 存储所点比萨的信息

pizza = {

    'crust': 'thick',

    'toppings': ['mushrooms', 'extra cheese'],

}

# 概述所点的比萨

print("You ordered a " + pizza['crust'] + "-crust pizza " + "with the following toppings:")

for topping in pizza['toppings']:

    print("\t" + topping)

二.一人有多种喜欢的语言。

favorite_languages = {

    'jen': ['python', 'ruby'],

    'sarah': ['c'],

    'edward': ['ruby', 'go'],

    'phil': ['phthon', 'haskell'],

}

for name, languages in favorite_languages.items():

    print("\n" + name.title() + "'s favorite languages are:")

    for language in languages:

        print("\t" + language.title())

三.language in languages,favorite_languages.items(),注意错误行是前面拼写不对造成。怎么用if语句检查喜欢的语言的门数?

四.pizza,crust,toppings,

favorite_languages = {

    'jen': ['python', 'ruby'],

    'sarah': ['c'],

    'edward': ['ruby', 'go'],

    'phil': ['python', 'haskell'],

}

for name, languages in favorite_languages.items():

    if len(languages) == 1:

        print("\n" + name.title() + "'s favorite language is:")

        for language in languages:

            print("\t" + language.title())

    else:

        print("\n" + name.title() + "'s favorite languages are:")

        for language in languages:

                print("\t" + language.title())

五.干,看,写,输,想,翻,试!不停留,顽强,坚持!时间,生命。列表和字典的嵌套层级不能太多,对比示例简化。

六.pizza.py,favorie_languages.py,

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Python去除字符串前后空格的几种方法
Python和Ruby先学哪个?
TIOBE Index | TIOBE
The homogenization of scientific computing, or why Python is steadily eating other languages’ lunch
Erlang vs Python
《与孩子一起学编程》第一章出发吧之学习编程、运行程序|中国少儿编程网
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服