乘法表:
a = 1
while a <= 9 :
b = 1
while b <= a :
print(str(b)+"*"+str(a)+"="+str(b*a),end="\t")
b += 1
print()
a += 1
#print("\n".join("\t".join(["%s*%s=%s" %(x,y,x*y) for y in range(1, x+1)]) for x in range(1, 10)))
login:
# user = "abc"
# key = "123"
#
# for i in range(3):
# user_name = input("user_name:")
# password = input("password:")
# if user_name ==user and password == key:
# print("welcome %s login..."%user)
# break
# else:
# print("invalid user_name or password")
# else:
# print("密码输入次数过多")
user = "abc"
key = "123"
counter = 0
while counter < 3:
user_name = input("user_name:")
password = input("password:")
if user_name ==user and password == key:
print("welcome %s login..."%user)
break
else:
print("invalid user_name or password")
counter += 1
if counter == 3:
keep_going_choice = input("do you want to login?[y/n]")
if keep_going_choice == "y":
counter = 0
else:
print("密码输入次数过多")
shopping:
a_list = [("iphone","8000"),("mac book","9000"),("coffee","32"),("Python book","80"),("bicyle","1500")]
salary = input("how much money you have:")
shopping_car = []
if salary.isdigit():
salary = int(salary)
while True:
for i,v in enumerate(a_list,1):
print(i,v)
choice = input("选择商品编号【退出:q】")
if choice.isdigit():
choice = int(choice)
if choice > 0 and choice <= len(a_list):
p_item = a_list[choice-1]
if int(p_item[1]) < salary:
salary -= int(p_item[1])
shopping_car.append(p_item)
else:
print("余额不足,还剩%s"%salary)
print(p_item)
elif choice =="q":
print("------------您已购买以下商品-------------")
for i in shopping_car:
print(i)
print("你还剩%s元钱"%salary)
break
else:
print("invalid input")
三級菜单:
menu = {
'北京': {
'朝阳': {
'国贸':{
'CICC':{},
"HP":{},
'CCTV':{}
},
'望京':{
'默默':{},
"奔驰":{},
'360':{}
},
'三里屯':{
'优衣库':{},
"apple":{},
}
},
'昌平': {
'沙河':{
'老男孩':{},
'阿泰包子':{}
},
'天通苑':{
'链家': {},
'我爱我家': {}
},
"回龙观":{},
},
'海淀':{
'五道口':{
'谷歌':{},
'网易':{},
'搜狐':{},
'shougou':{},
},
'中关村':{
'youku':{},
'汽车之家':{},
}
}
},
'上海':{},
'山东':{}
}
layer = menu
flayer = []
while True:
for i in layer:
print(i)
choice = input('输入').strip()
if len(choice) == 0:continue
if choice in layer:
flayer.append(layer)
layer = layer[choice]
elif choice == "b":
if flayer:
layer = flayer.pop()
elif choice == "p":
break
else:
print('无此项')
05-28