有些害羞。。。学生查询v3.0
经过一段时间的气质(弃置)后,我把Python捡了回来第一个练手的目标就是学生查询
我在电脑上搜了有一段时间才把他找到
本次更改内容:美化界面
上源码:from time import sleep
from random import randint
def print_all():
print("现在打印所有学生的档案:")
sleep(1)
if not (data == []):
for student in data:
print("学生ID: %s" % student["ID"], end = " ")
sleep(1)
print("姓名:%s" % student["name"], end=" ")
sleep(1)
print("性别:%s" % student["sex"], end=" ")
sleep(1)
print("地址:%s" % student["address"], end=" ")
sleep(1)
print()
else:
print('一团干草默默飘过。。。')
def someThing_put_in():
ID = randint(100000000, 999999999)
try:
if ID in data:
ID = randint(100000000, 999999999)
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)
except:
print("有错误")
def write_student():
someBody = input("请输入学生全名(非小名):")
for j in data:
if j["name"] == someBody:
TA_new_name = input("请输入新名字:")
TA_new_ID = randint(100000000, 999999999)
if TA_new_ID in data:
TA_new_ID = randint(100000000, 999999999)
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)
for k in data:
if k["name"] == someBody:
data.remove(k)
def del_student():
someGuy = input("请输入学生全名(非小名):")
for find in data:
if find["name"] == someGuy:
print()
sleep(1)
print("Find it!")
sleep(2)
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('你的档案库为空!')
def extract():
global data
try:
with open('data.txt', encoding='utf-8') as f:
temp = []
for i in f:
if i.isdigit():
temp.append()
for i in temp:
temp_list = {}
temp_list['ID'] = int(i)
temp_list['name'] = i
temp_list['sex'] = i
temp_list['address'] = i
if temp_list not in data:
data.append(temp_list)
print('提取学生档案成功!')
except OSError:
raise FileNotFoundError("file 'data.txt' is not found")
try:
data = extract()
except:
data = []
print(" ****************************************")
print(" 欢迎使用学生管理系统v3.0")
print(" 1.显示所有学生")
print(" 2.新建学生档案")
print(" 3.查询学生信息")
print(" 4.修改学生档案")
print(" 5.删除学生档案")
print(" 6.提取学生数据")
print(" 0.退出")
print(" ****************************************")
print()
while True:
someThing = input("输入操作序号:")
if someThing == "0":
break
elif someThing == "1":
print_all()
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":
more_Thing = input("要提取还是读取(填R(读取)或S(保存)):")
if more_Thing == "R" or more_Thing == "r":
extract()
elif more_Thing == "S" or more_Thing == "s":
save()
可以考虑搞个 tkinter 啥的吧,更帅气{:10_256:} Daniel_Zhang 发表于 2021-2-22 18:42
可以考虑搞个 tkinter 啥的吧,更帅气
对了,能不能教我一下tkinter,我买了本书抄源代码抄到第3个就莫名其妙的出错,咋改都不行 靳子轩 发表于 2021-2-25 16:15
对了,能不能教我一下tkinter,我买了本书抄源代码抄到第3个就莫名其妙的出错,咋改都不行
额...这个怎么教
如果有代码问题的话,可以新开一个帖子,等有缘人帮忙解答
我当时跟着小甲鱼学的 tkinter,但是确实有一些还是没那么容易理解的
后面去b站找了另一位大佬的教程
Tkinter 做简单的窗口视窗 (GUI 莫烦 Python 教程)
思路就清晰了挺多的
Daniel_Zhang 发表于 2021-2-25 17:14
额...这个怎么教
如果有代码问题的话,可以新开一个帖子,等有缘人帮忙解答
多谢,我去学习啊 问一下,鱼币怎么得。。。
页:
[1]