看看这段代码
from time import sleepfrom random import randint
import pickle
data = [{"ID":1000000001, "name":"None", "sex":"男", "address":"青海"},
{"ID":1929489285, "name":"False", "sex":"女", "address":"computer"}]
while True:
#循环开头显示功能
print(" ****************************************")
print(" 欢迎使用学生管理系统v2.0(后续有3.0)")
print(" 1.显示所有学生")
print(" 2.新建学生档案")
print(" 3.查询学生信息")
print(" 4.修改学生档案")
print(" 5.删除学生档案")
print(" 6.提取学生数据")
print(" 0.退出")
print(" ****************************************")
print()
def print_all():
for student in data:
print(student)
pass
pass
def someThing_put_in():
ID = randint(1000000000, 9999999999)
try:
if ID in data:
ID = randint(1000000000, 9999999999)
except:
print("调试错误!")
someName = input("输入姓名:")
someSex = input("输入性别:")
someAddress = input("输入地址:")
student = {"ID":ID, "name":someName, "sex":someSex, "address":someAddress}
data.append(student)
def find_student():
print("为了确保您是管理员,请输入学生全名(非小名)")
somename = int(input())
try:
for i in data:
if i["name"] == somename:
print(i)
pass
pass
pass
except:
print("有错误")
def write_student():
someBody = input("请输入学生全名(非小名):")
for j in data:
if j["name"] == someBody:
TA_new_name = input("请输入新名字:")
TA_new_ID = randint(1000000000, 9999999999)
if TA_new_ID in data:
TA_new_ID = randint(1000000000, 9999999999)
else:
TA_new_sex = input("输入性别:")
TA_new_address = input("输入地址:")
NEW_student = {"ID":TA_new_ID, "name":TA_new_name, "sex":TA_new_sex, "address":TA_new_address}
data.append(NEW_student)
LAST_name = input("输入原先的名字:")
for k in data:
if k["name"] == LAST_name:
need_del = k
data.remove(need_del)
def del_student():
someGuy = input("请输入学生全名(非小名):")
for find in data:
if find["name"] == someGuy:
print("Find it!")
want_del = someGuy
data.remove(want_del)
someThing = input("Enter the num:")
if someThing == "0":
break
elif someThing == "1":
print_all()
continue
elif someThing == "2":
print("好的")
print()
sleep(1)
someThing_put_in()
elif someThing == "3":
print("OK")
print()
find_student()
elif someThing == "4":
print("OK")
sleep(1)
write_student()
elif someThing == "5":
print("OK")
print()
del_student()
但是。。。
============== RESTART: C:\Users\Administrator\Desktop\尝试1\学生查询.py =============
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:5
OK
请输入学生全名(非小名):None
Find it!
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\尝试1\学生查询.py", line 105, in <module>
del_student()
File "C:\Users\Administrator\Desktop\尝试1\学生查询.py", line 78, in del_student
data.remove(want_del)
ValueError: list.remove(x): x not in list
他喵的怎么回事啊 你要删除的元素不在列表内 排版做的不错 看着好舒服 wp231957 发表于 2020-6-7 16:49
你要删除的元素不在列表内
我当时看错误也是X没在列表内,但看代码,在DATA里面,是不是有NONE? Twilight6 发表于 2020-6-7 16:52
排版做的不错 看着好舒服
呢能看看是什么问题吗(别跟2楼理由一样) {:10_247:}{:10_247:}{:10_247:} 不用5的话;
============== RESTART: C:\Users\Administrator\Desktop\尝试1\学生查询.py =============
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:1
{'ID': 1000000001, 'name': 'None', 'sex': '男', 'address': '青海'}
{'ID': 1929489285, 'name': 'False', 'sex': '女', 'address': 'computer'}
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:2
好的
输入姓名:John
输入性别:man
输入地址:Kunmming
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:1
{'ID': 1000000001, 'name': 'None', 'sex': '男', 'address': '青海'}
{'ID': 1929489285, 'name': 'False', 'sex': '女', 'address': 'computer'}
{'ID': 3069584097, 'name': 'John', 'sex': 'man', 'address': 'Kunmming'}
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:3
OK
为了确保您是管理员,请输入学生全名(非小名)
John
{'ID': 3069584097, 'name': 'John', 'sex': 'man', 'address': 'Kunmming'}
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:4
OK
请输入学生全名(非小名):None
请输入新名字:True
输入性别:man
输入地址:NewYork
输入原先的名字:None
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:1
{'ID': 1929489285, 'name': 'False', 'sex': '女', 'address': 'computer'}
{'ID': 3069584097, 'name': 'John', 'sex': 'man', 'address': 'Kunmming'}
{'ID': 2795943994, 'name': 'True', 'sex': 'man', 'address': 'NewYork'}
****************************************
欢迎使用学生管理系统v2.0(后续有3.0)
1.显示所有学生
2.新建学生档案
3.查询学生信息
4.修改学生档案
5.删除学生档案
6.提取学生数据
0.退出
****************************************
Enter the num:0
>>> 靳子轩 发表于 2020-6-7 17:00
不用5的话;
from time import sleep
from random import randint
import pickle
data = [{"ID": 1000000001, "name": "None", "sex": "男", "address": "青海"},
{"ID": 1929489285, "name": "False", "sex": "女", "address": "computer"}]
while True:
# 循环开头显示功能
print(" ****************************************")
print(" 欢迎使用学生管理系统v2.0(后续有3.0)")
print(" 1.显示所有学生")
print(" 2.新建学生档案")
print(" 3.查询学生信息")
print(" 4.修改学生档案")
print(" 5.删除学生档案")
print(" 6.提取学生数据")
print(" 0.退出")
print(" ****************************************")
print()
def print_all():
for student in data:
print(student)
pass
pass
def someThing_put_in():
ID = randint(1000000000, 9999999999)
try:
if ID in data:
ID = randint(1000000000, 9999999999)
except:
print("调试错误!")
someName = input("输入姓名:")
someSex = input("输入性别:")
someAddress = input("输入地址:")
student = {"ID": ID, "name": someName, "sex": someSex, "address": someAddress}
data.append(student)
def find_student():
print("为了确保您是管理员,请输入学生全名(非小名)")
somename = int(input())
try:
for i in data:
if i["name"] == somename:
print(i)
pass
pass
pass
except:
print("有错误")
def write_student():
someBody = input("请输入学生全名(非小名):")
for j in data:
if j["name"] == someBody:
TA_new_name = input("请输入新名字:")
TA_new_ID = randint(1000000000, 9999999999)
if TA_new_ID in data:
TA_new_ID = randint(1000000000, 9999999999)
else:
TA_new_sex = input("输入性别:")
TA_new_address = input("输入地址:")
NEW_student = {"ID": TA_new_ID, "name": TA_new_name, "sex": TA_new_sex, "address": TA_new_address}
data.append(NEW_student)
LAST_name = input("输入原先的名字:")
for k in data:
if k["name"] == LAST_name:
need_del = k
data.remove(need_del)
def del_student():
someGuy = input("请输入学生全名(非小名):")
for find in data:
if find["name"] == someGuy:
print("Find it!")
data.remove(find)
someThing = input("Enter the num:")
if someThing == "0":
break
elif someThing == "1":
print_all()
continue
elif someThing == "2":
print("好的")
print()
sleep(1)
someThing_put_in()
elif someThing == "3":
print("OK")
print()
find_student()
elif someThing == "4":
print("OK")
sleep(1)
write_student()
elif someThing == "5":
print("OK")
print()
del_student()
Twilight6 发表于 2020-6-7 17:00
试下
@Twilight6
大神顺便请教一下,做6的话给个初始方案,我修改下法作品展示 学生查询
https://fishc.com.cn/thread-171545-1-1.html
(出处: 鱼C论坛)
靳子轩 发表于 2020-6-7 17:27
学生查询
https://fishc.com.cn/thread-171545-1-1.html
(出处: 鱼C论坛)
你没@ 我 我都没看到消息 Twilight6 发表于 2020-6-8 17:46
你没@ 我 我都没看到消息
@Twilight6
sorry,才升到鱼油I,没法@你 靳子轩 发表于 2020-6-8 22:06
@Twilight6
sorry,才升到鱼油I,没法@你
想提取成一个文件是吧? no,后来我加了一个使用Pickle保存data的pkl,但是老出错,就暂时放弃了
@Twilight6 靳子轩 发表于 2020-6-8 22:12
no,后来我加了一个使用Pickle保存data的pkl,但是老出错,就暂时放弃了
@Twilight6
那可以不用 pickle 呀 ,用普通文件 参见:
学生查询
https://fishc.com.cn/thread-171545-1-1.html
(出处: 鱼C论坛)
@Twilight6 我发个附件:
@Twilight6 靳子轩 发表于 2020-6-8 22:16
@Twilight6
你输入 6 然后输入 0然后去看看data文件
from time import sleep
from random import randint
data = [{"ID": 1000000001, "name": "None", "sex": "男", "address": "青海"},
{"ID": 1929489285, "name": "False", "sex": "女", "address": "computer"}]
while True:
# 循环开头显示功能
print(" ****************************************")
print(" 欢迎使用学生管理系统v2.0(后续有3.0)")
print(" 1.显示所有学生")
print(" 2.新建学生档案")
print(" 3.查询学生信息")
print(" 4.修改学生档案")
print(" 5.删除学生档案")
print(" 6.提取学生数据")
print(" 0.退出")
print(" ****************************************")
print()
def print_all():
for student in data:
print(student)
pass
pass
def someThing_put_in():
ID = randint(1000000000, 9999999999)
try:
if ID in data:
ID = randint(1000000000, 9999999999)
except:
print("调试错误!")
someName = input("输入姓名:")
someSex = input("输入性别:")
someAddress = input("输入地址:")
student = {"ID": ID, "name": someName, "sex": someSex, "address": someAddress}
data.append(student)
def find_student():
print("为了确保您是管理员,请输入学生全名(非小名)")
somename = input()
try:
for i in data:
if i["name"] == somename:
print(i)
pass
pass
pass
except:
print("有错误")
def write_student():
someBody = input("请输入学生全名(非小名):")
for j in data:
if j["name"] == someBody:
TA_new_name = input("请输入新名字:")
TA_new_ID = randint(1000000000, 9999999999)
if TA_new_ID in data:
TA_new_ID = randint(1000000000, 9999999999)
else:
TA_new_sex = input("输入性别:")
TA_new_address = input("输入地址:")
NEW_student = {"ID": TA_new_ID, "name": TA_new_name, "sex": TA_new_sex, "address": TA_new_address}
data.append(NEW_student)
LAST_name = input("输入原先的名字:")
for k in data:
if k["name"] == LAST_name:
need_del = k
data.remove(need_del)
def del_student():
someGuy = input("请输入学生全名(非小名):")
for find in data:
if find["name"] == someGuy:
print()
sleep(1)
print("Find it!")
data.remove(find)
def save():
if data!= []:
with open('data.txt','w',encoding='utf-8') as f:
f.write('{:^10}{:^10}{:^10}{:^10}\n\n'.format('ID','Name','Sex','Address'))
for i in data:
f.write('{:^10}{:^10}{:^10}{:^10}\n\n'.format(i['ID'],i['name'],i['sex'],i['address']))
print('保存数据成功!')
else:
print('你的档案库为空!')
someThing = input("Enter the num:")
if someThing == "0":
break
elif someThing == "1":
print_all()
continue
elif someThing == "2":
print("好的")
print()
sleep(1)
someThing_put_in()
elif someThing == "3":
print("OK")
print()
find_student()
elif someThing == "4":
print("OK")
sleep(1)
write_student()
elif someThing == "5":
print("OK")
print()
del_student()
elif someThing == "6":
save()
页:
[1]
2