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)
  • 相关阅读:
    CCNode作为容器实现显示区域剪裁
    使用CCNode作为容器容易踩的坑
    走了很多弯路的CCScrollView
    常用es6特性归纳-(一般用这些就够了)
    WebP图片优化
    es6 Promise 异步函数调用
    网站性能优化
    dom元素分屏加载
    js顺序加载与并行加载
    移动端真机调试
  • 原文地址:https://www.cnblogs.com/xusuns/p/8117852.html
Copyright © 2011-2022 走看看