跳出多层循环
#!/bin/bash
# -*- coding:utf-8 -*-
for i in range(1,100):
for x in range(1,100):
for y in range(1,100):
print(i,x,y)
exit()
购物程序
#!/bin/bash
# -*- coding:utf-8 -*-
#变量
goods_list = {
"something1" : 100,
"something2" : 20,
"something3" : 50,
"weed" : 75,
"Marlboro" : 15,
"heroin" : 325
}
bought_list = [] #购买列表
count = 0 #商品序号
goods_name = list(goods_list.keys())
#函数
def get_price(choice):
name = goods_name[choice]
return name,goods_list[name]
#主程序
#input
while True:
user_salary = input("请输入你的资金:")
if user_salary.isdigit():
user_salary = int(user_salary)
break
#menu
print("--------goods store--------")
for x in goods_name:
print("%s. %s ---- %s" %(count,x,goods_list[x]))
count += 1
print("--------goods store--------")
#bought
while True:
list_choice = input("请输入要购买的商品编号:")
if list_choice.isdigit():
list_choice = int(list_choice)
if list_choice >= 0 and list_choice < len(goods_list):
bought_name,bought_price = get_price(list_choice)
if user_salary - bought_price >= 0:
bought_list.append(bought_name)
user_salary = user_salary - bought_price
print("目前余额:%s" %user_salary ,"您购买的商品:",bought_list)
else:
print("你的资金不足以购买")
else:
print("错误的选择")
still_choice = input("继续?y/n")
if still_choice == 'n' or still_choice == 'N':
print("您的余额为%s" %user_salary)
exit()