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