// 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('格式错误')
Python-Whilewhile循环实例1// An highlighted blocksign =Truequestionnaire ={}while sign: name =input('您的名称是:') place =input('您喜欢的地方是:') questionnaire[name] = place #创建键值对 select =input...