python-作业2

来源:互联网 发布:亚马逊订单管理 软件 编辑:程序博客网 时间:2024/06/07 23:32


#######################################作业##############################3

1
,登陆
import time
a = '''
(C)reate:
(L)ogin:
(D)elete:
(V)iew:
   
input your choice:
'''

while True:
   
choice = raw_input(a).lower()
   
dic = {"user1":"123", "user2": "234"}
if choice == 'c':
   
newuser =raw_input("username:")
   
newpassword =raw_input("password:")
   
dic[newuser] = newpassword
   
print newuser
   print "
新用户创建成功!"
elif choice == 'l':
   
user =raw_input("username:")
   
password =raw_input("password:")
   
if user in dic and dic[user]==password:
       print "
登陆成功!"
   
else:
       print "
请输入正确的用户名和密码!"
elif choice == 'd':
   
user =raw_input("username:")
   password = raw_input("password
")
   
if user not in dic:
       print "
该用户不存在!"
   
elif dic[user]!= password:
       print "
密码不正确!"
   
else:
       print "
删除成功!"
elif choice == 'v':
   
user =raw_input("username:")
   
password =raw_input("password:")
   if 
user not in dic:
       print "
该用户不存在!"
   
elif dic[user]!= password:
       print "
密码不正确!"
   
else:
       
print user
       print "
正常显示!"
else:
    print "
请重新输入!"



2
,购物车
dic = []
salary = input("your salary:")
shopinfo = [
   
('iphone',1000),
   
('book',100),
   
('bike',200)
]
for k,v in enumerate(shopinfo):
   
print k,v
num = input("num:")
if num == 0:
   
print "added [iphone] to yourshopping"
   
if salary < 1000:
       print "
您的余额不足!"
   
else:
       
dic.append('iphone')
elif num == 1:
   
print "added [book] to yourshopping"
   
if salary < 100:
       print "
您的余额不足!"
   
else:
       
dic.append('book')
elif num == 2:
   
print "added [bike] to yourshopping"
   
if salary < 200:
       print "
您的余额不足!"
   
else:
       
dic.append('bike')
tuichu = input("quit:")
if tuichu == 'q':
   
quit(shopinfo)
   print k,v in enumerate(dic)

原创粉丝点击