zoukankan      html  css  js  c++  java
  • while循环 动手试一试

    1.创建一个三明治列表,其中包含各种三明治名,至少保证‘pastrami’出现三次,在创建一个空列表,对每种三明治打印一条信息,比如i made your tuna sandwich,并将其移动空列表中,所有三明治制作好后,打印一条消息,将这些三明治都列出了。

    orders=['Arepa','Pastrami','Croque Madame','Smoked Meat','Pastrami','Doner Kebab','Arepa','Pastrami','Tuna']
    finished=[]
    while orders:
        a=orders.pop()
        print('I made your %s sandwich.'%(a))
        finished.append(a)
    print(sorted(finished))

    2.在开头打印一条消息,指出pastrami已经卖完了,在使用一个循环将order中的pastrami删除,确认最终的列表中不含有pastrami

    orders=['Arepa','Pastrami','Croque Madame','Smoked Meat','Pastrami','Doner Kebab','Arepa','Pastrami','Tuna']
    finished=[]
    print('Pastrami is sold out.')
    while 'Pastrami' in orders:
        orders.remove('Pastrami')
    while orders:
        a=orders.pop()
        print('I made your %s sandwich.'%(a))
        finished.append(a)
    print(sorted(finished))

    3.调查用户梦想度假胜地,并编写一个打印调查结果代码块

    dic={}
    flag=True
    while flag:
        name=input('What is your name?')
        place=input('If you could visit one place in the world,where would you go?')
        dic[name]=place
        a=input('Anyone else? or quit')
        if a.lower() =='quit':
            flag=False
    for i,v in dic.items():
        print(i,'want to visit',v)
  • 相关阅读:
    unity vscode 断点问题
    unity Prefab 序列化一个小问题。
    公司有同事中病毒
    有点愧疚,今天把unity官方骗了...
    网络处理,发送约定
    (转载)MonoBehaviour的事件和具体功能总结
    控制台输出乱码问题
    vs遇到的字符串问题
    cmake的下载和安装
    三消设计思路, 通过配置文件搞定一切。
  • 原文地址:https://www.cnblogs.com/xusuns/p/8117852.html
Copyright © 2011-2022 走看看