您的位置:首页 > 编程语言 > Python开发

python-作业2

2017-07-11 21:23 176 查看


#######################################作业##############################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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: