zoukankan      html  css  js  c++  java
  • python基础02

    跳出多层循环


    #!/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()
    
  • 相关阅读:
    排球运动规则简介
    我与计算机
    我和电脑的不解之缘
    作业
    怎样成为一个高手 观后感
    本周作业
    作业个人
    本周作业
    本周总结
    本周总结(13周)
  • 原文地址:https://www.cnblogs.com/anyanyaaaa/p/6635821.html
Copyright © 2011-2022 走看看