一、字符串
names.xxx
二、列表 购物车程序
print(‘Please in put your salary:’)
salary=int(input())
goods=[[1,‘iphone’,5888],
[2,‘ipad’,3888],
[3,‘mac’,7888],
[4,‘iwatch’,2588],
[5,‘airpods’,1188]]
buyed=[]
while salary>0:
print(goods)
print(‘Chose your goods’)
count=input(‘chose’)
if count!=‘n’:
count=int(count)
if count>5 or count<0:
print(‘out of list ,chose again’)
continue
else:
if salary>=goods[count-1][2]:
buyed.append(goods[count-1])
else:
print(‘salary=’,salary)
print(‘salary is not enough,please chose again or not’)
time=input()
if time!=‘n’:
continue
else:
print(‘think you’)
break
salary = salary - goods[count - 1][2]
else:
print(‘think you’)
break
buyed.pop()
print(buyed)
print(‘salary=’,salary)
三、字典 三级菜单程序 ‘’'多级菜单 1
)三级菜单
2)可依次选择进入各子菜单
3)可依次退至上一级菜单或直接退至初始菜单
4)所需知识点:列表/字典
‘’’
data={‘上海’:{
‘浦东’:{
‘临港’:[‘上海海洋大学’,‘上海海事大学’,‘上海电机学院’]
},
‘奉贤’:{
‘海湾’:[‘华东理工’,‘上海师范’,‘旅游专科’]
},
‘其他’:{
‘其他区’:[‘上海大学’,‘工技大’,‘交大’]
}
},
‘浙江’:{…},
‘江苏’:{…}
}
exit_flag=False
while not exit_flag:
for i1 in data:
print(i1)
choice=input(‘选择》》》’)
if choice in data:
while not exit_flag:
for i2 in data[choice]:
print(i2)
choice2=input(‘选择》》》’)
if choice2 in data[choice]:
while not exit_flag:
for i3 in data[choice][choice2]:
print(i3)
choice3=input(‘选择》》》’)
if choice3 in data[choice][choice2]:
for i4 in data[choice][choice2][choice3]:
print(i4)
choice4=input(‘按B返回’)
if choice4 == ‘b’:
pass
elif choice4 == ‘q’:
exit_flag = True
if choice3 == ‘b’:
break
elif choice3 == ‘q’:
exit_flag = True
if choice2==‘b’:
break
elif choice2==‘q’:
exit_flag = True