python-作业2

本文介绍了一个简单的用户管理系统,包括用户创建、登录、删除和查看等功能,并通过Python代码示例进行了说明。此外,还展示了一个基础购物车功能,允许用户选择商品并检查余额。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



#######################################作业##############################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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值