python实验脚本

day1

1.  任性猜数字

需求 : 猜数字, 猜3次。如果对了 就直接退出。 如果3次都错了 ,就询问 要不要继续。

实现点: 使用 whie 循环。 count 进行计数。如果count >=3(猜错3次了)  就询问(交互式,输入N/n 退出)要不要继续, 如果继续,count归0 。重新开始。

 

# Author ricky

age_of_name = 56

count = 0
while count < 3 :
     age= int(input("age:"))
     if age_of_name == age:
          print ("you got it.")
          break
     elif age_of_name > age:
          print ("think bigger.")
     else:
           print ("think smaller.")
     count = count + 1
     if count == 3:
          flag_guess = input ("do you want continue. N/n(exit)/default(continue)")
          if flag_guess  !=  ("N") and flag_guess  !=  ("n") :
               count = 0

 

 

day 2

购物车脚本

# Author ricky

products_list=[
    ("mac","10000"),
    ("book","60"),
    ("bick","800"),
    ("coffee","30"),
    ("T_shirt","100")
]

shopping_list=[]

while True:
    salary = input("Please input  your salary:")
    if salary.isdigit():
        salary = int(salary)
        while True:
            for index,item in enumerate(products_list):
                print  ( index, item )
            user_choise = input("input  your choise:")
            if user_choise.isdigit():
                user_choise = int(user_choise)
                if user_choise >= 0  and user_choise < len(products_list):
                    p_item = products_list[user_choise]
                    p_money = int(p_item[1])
                    if salary >= p_money:
                        shopping_list.append( p_item )
                        salary = salary - p_money
                        print  ("You have bought \033[31;1m%s\033[0m,and  you current balance is  \033[32;1m%s\033[0m" %(shopping_list,salary))
                    else:
                        print( "You do not have enough  money, You current balance is \033[31,1m%s\033.[0m" %salary )
                else:
                    print ("Invaild input")
            elif user_choise ==  ("q"):
                print ("---------------  shopping_list---------------")
                print (shopping_list,"Your current balance is \033[31;1m%s\033[0m" %salary )
                exit()
            else:
                print (" Input  serise number")
    else:
        print ("Please input  num")

 

 

 

day2  三级菜单

# Author ricky

data = {
    "猫腻": {
        "间客":{
            "male":"徐乐",
            "female": "张小萌"
        },
        "择天记":{
            "male":"长生" ,
            "famale":"有容"
        },
        "庆余年": {
            "male":"范暹" ,
            "famale":"千落"
        }
    },
    "唐三":{
        "狂神":"",
        "善良的死神":"",
        "斗罗大陆" : ""
    },
    "烟雨江南": {
        "亵渎":"",
        "罪恶之城":"",
        "小二":""
    }
}

exit_flag = True

while exit_flag:
    for  i  in data:
        print (i)
    print   ( "you can  inpint  place " , "b is return"," q is exit" )
    choise1 = input ("Please choise:" )
    if choise1 in data:
        while exit_flag:
            for  i2 in  data[choise1]:
                print  ("\t",i2)
            print("you can  inpint  place ", "b is return", " q is exit")
            choise2 = input("Please choise:")
            if choise2 in data[choise1]:
                while exit_flag :
                    print (data[choise1][choise2])
                    print ("the last level,while reture B: reture Q:exit")
                    choise3 = input ("Please choise:")
                    if choise3 == "b":
                        break
                    elif choise3 =="q":
                        exit_flag = False
            elif choise2 == ("q"):
                exit_flag = False
            elif choise2 == ("b"):
                break
    elif choise1 == ("q") :
        exit_flag = False

 

转载于:https://www.cnblogs.com/rockyricky/p/10505487.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值