import sys
import json
a = 'py1807'
all_student = {'user1': ['hjj', {'name': 'hjj', 'age': 12, 'phone': 1234, 'stu_id': 'py1807000'}]}
bian = '* '*30
f = '>>>>'
# lstrip()
def add_student(user):
global f
global bian
pd = 1
while pd == 1:
with open('/Users/hujianjun/Desktop/student.json', 'r') as f:
stu_message = json.load(f)
num = stu_message[user][len(stu_message[user]) - 1]['stu_id']
new_num = ''
for x in num[6:10]:
new_num += x
new_num = str(new_num).lstrip('0')
num = int(new_num) + 1
stu_id = '%s%s' % (a, str(num).rjust(4, '0'))
stu_name = input('请输入学生姓名:'.rjust(19, ' '))
stu_age = input('请输入学生年龄:'.rjust(19, ' '))
stu_phone = input('请输入学生电话:'.rjust(19, ' '))
stu_message[user].append(stu_name)
stu_message[user].append({'name': stu_name, 'age': stu_age, 'phone': stu_phone, 'stu_id': '%s' % stu_id})
with open('/Users/hujianjun/Desktop/student.json', 'w') as f1:
json.dump(stu_message, f1)
print('添加成功!!!'.rjust(19, ' '))
b = '1.继续添加'
c = '2.返回上一页'
pd11 = input('%s\n%s\n%s\n%s' % (bian.rjust(71, ' '), b.rjust(41, ' '), c.rjust(42, ' '),
bian.rjust(71, ' ')))
if pd11 == '2':
break
elif pd11 == '1':
continue
else:
b = '你的输入有误返回到上一层'
print('%s\n' % b.rjust(44, ' '))
break
def select_student(user):
global f
global bian
pd = 2
while pd == 2:
b = '1.查询所有学生信息'
c = '2.根据学生姓名查询信息'
pd_select = input('%s\n%s\n%s\n%s' % (bian.rjust(71, ' '), b.rjust(41, ' '), c.rjust(42, ' '), bian.rjust(71, ' ')))
with open('/Users/hujianjun/Desktop/student.json', 'r') as f:
stu_message = json.load(f)
if pd_select == '1':
for x in stu_message[user]:
print(' '*10, x)
b = '1.继续查询'
c = '2.返回上一页'
pd11 = input('%s\n%s\n%s\n%s' % (bian.rjust(71, ' '), b.rjust(41, ' '), c.rjust(42, ' '), bian.rjust(71, ' ')))
if pd11 == '2':
break
elif pd11 == '1':
pass
else:
b = '你的输入有误请重新输入'
print('%s\n' % b.rjust(44, ' '))
continue
elif pd_select == '2':
name_index = 0
stu_pd = 0
b = '请输入你想要查询的学生姓名:'
name_select = input('%s' % b.rjust(42, ' '))
for x in stu_message[user]:
name_index += 1
if name_select == x:
print(' '*10, stu_message[user][name_index])
stu_pd = 1
if stu_pd == 0:
b = '你查找的学生不存在'
print('%s' % b.rjust(40, ' '))
b = '1.继续查询'
c = '2.返回上一页'
pd11 = input('%s\n%s\n%s\n%s' % (bian.rjust(71, ' '), b.rjust(41, ' '), c.rjust(42, ' '), bian.rjust(71, ' ')))
if pd11 == '2':
break
elif pd11 == '1':
pass
else:
b = '你的输入有误返回到上一层'
print('%s\n' % b.rjust(44, ' '))
break
else:
b = '你的输入有误重新输入'
print('%s\n' % b.rjust(44, ' '))
continue
def delete_student(user):
pd = 3
global f
global bian
while pd == 3:
pd_delete = input('请输入你想要删除的学生姓名:')
index = 0
name_index = []
name_pd = 0
with open('/Users/hujianjun/Desktop/student.json', 'r') as f:
stu_message = json.load(f)
if len(stu_message[user]) == 1:
print('学生信息为空无法进行删除操作,返回到主页面')
break
else:
for x in stu_message[user][:]:
index += 1
if pd_delete == x:
name_index.append(index)
name_pd = 1
if name_pd == 0:
print('你输入的学生不存在,请重新输入')
continue
print(len(name_index))
for x1 in range(len(name_index)):
print('序号:%d' % name_index[x1], stu_message[user][name_index[x1]])
qr_delete = input('请确认删除信息,输入序号进行删除,r.重新输入,q.返回上一层\n')
if qr_delete == 'r':
continue
elif qr_delete == 'q':
break
else:
if int(qr_delete) not in name_index[:]:
print(qr_delete, name_index)
print('你输入序号有误重新输入')
else:
qr = int(qr_delete)
stu_message[user].pop(qr)
stu_message[user].pop(qr-1)
with open('/Users/hujianjun/Desktop/student.json', 'w') as f:
json.dump(stu_message, f)
# del stu_message[user][int(qr_delete)-1]
# del stu_message[user][int(qr_delete)]
print('删除成功')
qr_1_delete = input('1.继续删除2返回上一层')
if qr_1_delete == '1':
continue
elif qr_1_delete == '2':
break
else:
print('输入信息有误返回到上一层!')
def manue(user):
while True:
print(' '*10, '* * * * * * * * * * * * hjj学生管理系统 * * * * * * * * * * *\n'
' * *')
b = '2.查找学生'
c = '3.删除学生'
d = '4.退出系统'
e = '* '*30
g = '* *'
a = '1.添加学生\n%s\n%s\n%s\n%s\n%s\n%s\n%s' % (g.rjust(70, ' '), b.rjust(41, ' '), g.rjust(70, ' '),\
c.rjust(41, ' '), g.rjust(70, ' '),d.rjust(41, ' '), e.rjust(71, ' '))
pd1 = input(a.rjust(452, ' '))
if pd1 == '1':
add_student(user)
elif pd1 == '2':
select_student(user)
elif pd1 == '3':
delete_student(user)
elif pd1 == '4':
sys.exit()
else:
b = '你的输入有误请重新输入'
print('%s\n' % b.rjust(44, ' '))
pd1 = '1'
# manue('user1')
def login():
while True:
print('1.登录')
print('2.注册')
login_pd = input()
with open('/Users/hujianjun/Desktop/user.json', 'r') as f:
user_massage = json.load(f)
if login_pd == '2':
while True:
user = input('请输入账号')
pwd = input('请输入密码')
message = {user: pwd}
pd = 0
for x in user_massage:
if x == user:
pd = 1
print('该账号已经被注册!请重新注册')
continue
if pd == 0:
user_massage[user] = pwd
print(user_massage)
with open('/Users/hujianjun/Desktop/user.json', 'w') as f1:
json.dump(user_massage, f1)
with open('/Users/hujianjun/Desktop/student.json', 'r') as f:
user_massage = json.load(f)
user_massage[user] = ['hjj', {'name': 'hjj', 'age': 12, 'phone': 1234, 'stu_id': 'py18070001'}]
with open('/Users/hujianjun/Desktop/student.json', 'w') as f2:
json.dump(user_massage, f2)
print('注册成功!!返回到主页')
break
elif login_pd == '1':
while True:
user = input('请输入账号')
pwd = input('请输入密码')
pd1 = 0
for x in user_massage:
if user == x:
pd1 = 1
if user_massage[x] == pwd:
pd1 = 2
break
if pd1 == 2:
manue(user)
elif pd1 == 1:
print('密码错误!请重新输入')
elif pd1 == 0:
print('账户不存在请查证后输入')
login()
2018-10-15作业
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 小学语文修改病句的方法 修改病句是小学语文考试中常见的题型,在修改病句之前,我们应该清晰的了解有哪些病句现象,下面...
- 写在前面的话: 大家回忆一下我们第一节课给大家分享的吴军老师提出的在大学学什么: 1 付诸行动的习惯2 沟通能力和...