Python学习第二周

一、字符串

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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值