7.30每日学习课后作业之函数的使用

# 默写:
# 函数中参数的分类及其作用
# 位置
# 关键字
# 形参
# 实参
# 可变长度参数
#
# 练习题:
# 1.
# 使用函数新的知识点继续完善, 优化购物车
import os
product_list = [['Iphone7',5800],
['Coffee',30],
['疙瘩汤',10],
['Python Book',99],
['Bike',199],
['ViVo X9',2499],]
shoppint_cart={}
current_userinfo=[]
db_file=r'db.txt'
while True:
print("""
1 登陆
2 注册
3 购物
""")
choice=input('选择>>>:')
if choice=='2':
name=input('用户名>>>:').strip()
while True:
pwd=input('密码>>>>:')
pwd1=input('确认密码>>>>:')
if pwd==pwd1:
print('注册成功')
break
else:
print('两次密码不一致,请重新输入')
amount=input('充值金额:')
with open(db_file,mode='a',encoding='utf-8')as f:
f.write('%s,%s,%s\n'%(name,pwd,amount))
elif choice=='1':
tag=True
count=0
while tag:
if count==3:
print('\033[45m尝试次数过多,退出。。。\033[0m')
break
uname=input('用户名:').strip()
pwd = input('密码:').strip()
with open(db_file,mode='r',encoding='utf-8') as f:
for line in f:
line = line.strip('\n')
user_info = line.split(',')
uname_of_db = user_info[0]
pwd_of_db = user_info[1]
balance_of_db = int(user_info[2])

if uname == uname_of_db and pwd == pwd_of_db:
print('\033[48m登陆成功\033[0m')

# 登陆成功则将用户名和余额添加到列表
current_userinfo = [uname_of_db, balance_of_db]
print('用户信息为:', current_userinfo)
tag = False
break
else:
print('\033[47m用户名或密码错误\033[0m')
count +=1
elif choice=='3':
pass

















# 2.
# 使用函数完成以下功能, 数据格式如下
# [
# {“name”:”张无忌”, ”number”, ”sh01”, ”math”:90,”english”:87,”chinese”:56},
# {“name”:”武则天”, ”number”, ”sh02”, ”math”:40,”english”:97,”chinese”:67}....
# ]
# 提供以下功能函数
# 获取指定学生的成绩
# 获取指定学号的成绩
# 根据学生的学号修改姓名
# 根据姓名修改指定学科的成绩
# 删除指定学生及其成绩
# list1=[ {"name":"张无忌", "number":"sh01",'grade':{"math":90,"english":87,"chinese":56}},
# {"name":"武则天", "number":"sh02",'grade':{ "math":40,"english":97,"chinese":67}},
# ]
# def stu_score(name):
# for i in list1:
# if name == i['name']:
# for j in i['grade']:
# print('%s %s' %(j,i['grade'][j]))
# return
# stu_score('武则天')

# def stu_number(num):
# for i in list1:
# if num == i['number']:
# for j in i['grade']:
# print('%s %s' % (j, i['grade'][j]))
# return
# stu_number('sh02')

# def stu_modify(num,new_name):
# for i in list1:
# if num == i['number']:
# print(i['grade'])
# i['name']=new_name
# print(list1)
# return
# stu_modify('sh02','alex')

# def pro_modify(name,project,socre):
# for i in list1:
# if name == i['name']:
# i['grade'][project]=socre
# print(list1)
# return
# pro_modify('武则天','english','99')

# def del_stuascore(name):
# for i in list1:
# if name==i['name']:
# list1.remove(i)
# print(list1)
# del_stuascore('武则天')


# 3.
# 博客作业
# http: // www.cnblogs.com / linhaifeng / articles / 7531972.html # _label5







# 拓展:
# ATM
# 参考博客

猜你喜欢

转载自www.cnblogs.com/Maikes/p/9458861.html