Python --While循环

Python-While

while循环实例1

// An highlighted block
sign =True
questionnaire ={}
while sign:
    name =input('您的名称是:')
    place =input('您喜欢的地方是:')
    questionnaire[name] = place #创建键值对
    select =input('您选择继续输入吗,继续为yes,退出为no')
    if select =='no':
        sign =False
for n,y in questionnaire.items():
    print(n+'喜欢的地址是:'+y)

while循环实例2

sandwich_orders = ['banana_sandwich','apple_sandwich','milk_sandwich','pastrami','pastrami','pastrami']
#三明治的列表
finished_sandwich =[]
#循环列表中的值 赋值给新列表
for i in sandwich_orders:
    print('i made '+i)
    finished_sandwich.append(i)
print(finished_sandwich)
print('pastrami sell out ')
pastrami1 =True
#如果标识pastrami1 =True则继续while循环为False不循环
while pastrami1:
    if 'pastrami' in finished_sandwich :
        #有过列表存在pastrami则删除
        finished_sandwich.remove('pastrami')
    else:
        pastrami1= False
print(finished_sandwich)

while循环实例3

sign =True
while sign :
    try:
        age = int(input('请输入您的年龄:'))
        if age>=12:
            print('您的票价为15元')
        elif age>=3 and age<=12:
            print('您的票价为10元')
        elif age<3:
            print('您的票价为5元')
        abc=input('是否继续买票?yes为继续买票,no为退出买票')
        if  abc =='no':
            sign =False
    except Exception as e:
        print('格式错误')

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值