鱼C论坛

 找回密码
 立即注册
查看: 2329|回复: 3

[已解决]查询学生信息报错

[复制链接]
发表于 2021-5-16 01:00:14 | 显示全部楼层 |阅读模式
4鱼币
  1. def search():   # 2.查找学生信息
  2.     student_query = []  # 建一个列表
  3.     while True:  #循环
  4.         id = ''
  5.         name = ''
  6.         if os.path.exists(filename):
  7.             mode = input('按ID查找请输入1,按姓名查找请输入2:')
  8.             if mode == '1':
  9.                 id = input('请输入学生的ID:')
  10.             elif mode == '2':
  11.                 name = input('请输入学生姓名')
  12.             else:
  13.                 print('您的输入有误,请重新输入')
  14.                 search()  #如果输入错误 就重新调用自己
  15.             with open(filename,'r',encoding='utf-8') as rfile:
  16.                 student = rfile.readlines()  #读取所有内容
  17.                 for item in student:
  18.                     d =dict(eval(item))
  19.                     if id != '':  # id不等于空
  20.                         if d['id'] == id:   #如果相等
  21.                             student_query.append(d)   #将他加入到 query列表当中
  22.                     elif name != '':
  23.                         if d['name'] == name: #如果相等
  24.                             student_query.append(d)   #将他加入到 query列表当中
  25.             #显示查询结果
  26.             show_student(student_query)
  27.             #清空列表
  28.             student_query.clear()
  29.             anser = input('是否要继续查询?y/n\n')
  30.             if anser =='y':
  31.                 continue
  32.             else:
  33.                 break
  34.         else:
  35.             print('暂未保存学生信息')
  36.             return


  37. def show_student(lst):
  38.     if len(lst) == 0:
  39.         print('没有查询到学生信息,无数据显示!')
  40.         return
  41.     #定义标题的显示格式
  42.     format_title = '{:^6 \t {:^12} \t {:^8} \t {:^10} \t {:^10} \t {:^8}}'
  43.     print(format_title.format('ID','姓名','英语成绩','Python成绩','Java成绩','总成绩'))
  44.     #定义内容的显示格式
  45.     format_data = '{:^6 \t {:^12} \t {:^8} \t {:^10} \t {:^10} \t {:^8}}'
  46.     for item in lst:
  47.         print(format_data.format(item.get('id'),
  48.                                  item.get('name'),
  49.                                  item.get('English'),
  50.                                  item.get('Python'),
  51.                                  item.get('Java'),
  52.                                  int(item.get('English'))+int(item.get('Python'))+int(item.get('Java'))
  53.                                  ))
复制代码

报错
6.png
最佳答案
2021-5-16 01:00:15
{:^6 这个不是少了半个大括号吗

最佳答案

查看完整内容

{:^6 这个不是少了半个大括号吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-5-16 01:00:15 | 显示全部楼层    本楼为最佳答案   
{:^6 这个不是少了半个大括号吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-5-16 10:02:42 | 显示全部楼层
洋洋痒 发表于 2021-5-16 08:39
{:^6 这个不是少了半个大括号吗

谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-5-16 10:04:10 | 显示全部楼层
本帖最后由 wcq15759797758 于 2021-5-16 10:08 编辑
洋洋痒 发表于 2021-5-16 01:00
{:^6 这个不是少了半个大括号吗


可以啦大佬 谢谢啦!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 21:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表