欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實現(xiàn)簡易版學(xué)生成績管理系統(tǒng)

 更新時間:2020年06月22日 16:06:07   作者:Code進階狼人  
這篇文章主要為大家詳細介紹了python實現(xiàn)簡易版學(xué)生成績管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

300來行python代碼實現(xiàn)簡易版學(xué)生成績管理系統(tǒng),供大家參考,具體內(nèi)容如下

使用鏈表來實現(xiàn)

class Node(object):
 def __init__(self, data, pointer):
 self.data = data
 self.next = pointer


# 創(chuàng)建單鏈表
class SingleLinkedList(object):
 def __init__(self):
 self.head = Node(None, None)
 self.point = self.head

 def append(self, data):
 # 末尾追加節(jié)點
 new_node = Node(data, None)
 self.point.next = new_node
 self.point = new_node

 def insert(self, data, find):
 # 插入數(shù)據(jù)(前向插入數(shù)據(jù))
 if not self.head.next:
  print('鏈表為空')
  return None
 new_node = Node(data, None)
 self.point = self.head
 while self.point.next.data != find:
  self.point = self.point.next
  if self.point.next is None:
  print('沒有找到該元素')
  return None

 new_node.next = self.point.next
 self.point.next = new_node

 def delete(self, find):
 # 刪除節(jié)點
 # 空鏈表
 if not self.head.next:
  print('鏈表為空')
  return None
 self.point = self.head
 while self.point.next.data != find:
  self.point = self.point.next
 pointer = self.point.next
 self.point.next = self.point.next.next
 del pointer

 def insert_after_head(self, data):

 node = Node(data, None)
 # bug 產(chǎn)生沒寫 if 返回
 if not self.head.next:
  self.head.next = node
  return None
 node.next = self.head.next
 self.head.next = node

 def reverse(self):
 local_list = SingleLinkedList()
 self.point = self.head
 count = 0
 while self.point.next:
  count += 1
  self.point = self.point.next
  data = self.point.data
  local_list.insert_after_head(data)
 return local_list

 def get_size(self):
 count = 0
 self.point = self.head
 while self.point.next:
  self.point = self.point.next
  count += 1
 return count

 def delete_by_tail(self, num):
 size = self.get_size()
 assert (num <= size)
 assert (num > 0)
 pos = size - num
 count = 0
 self.point = self.head
 while count < size:
  count += 1
  self.point = self.point.next
  if count == pos:
  pointer = self.point.next
  self.point.next = self.point.next.next
  del pointer

 # 求中間節(jié)點 只允許遍歷一次
 def quick_middle(self):
 slow_point = self.head
 fast_point = self.head
 while fast_point.next.next:
  slow_point = slow_point.next
  fast_point = fast_point.next.next
  if not fast_point.next:
  break
 if fast_point.next:
  slow_point = slow_point.next
 return slow_point.data

 def check_circle(self):
 pass

 def sort(self):
 # get_size()改變了 self.point 的指向
 length = self.get_size()
 i, j = 0, 0
 flag = 1
 while i < length:
  self.point = self.head.next
  while j < length - i - 1:
  if self.point.data > self.point.next.data:
   temp = self.point.data
   self.point.data = self.point.next.data
   self.point.next.data = temp
  self.point = self.point.next
  j += 1
  flag = 0
  if flag:
  break
  i += 1
  j = 0

 def print(self):
 # 打印結(jié)點
 self.point = self.head
 while self.point.next:
  self.point = self.point.next
  print('{} ->'.format(self.point.data), end=' ')
 print('')


class StudentControlSystem(SingleLinkedList):
 # 打印菜單
 def print_menu(self):
 print('*' * 30)
 print('-' * 13 + '菜單' + '-' * 13)
 print('1.增加學(xué)生信息')
 print('2.刪除學(xué)生信息')
 print('3.修改學(xué)生信息')
 print('4.查找學(xué)生信息')
 print('5.顯示所有信息')
 print('6.排序')
 print('0.退出程序')
 print('*' * 30)

 # 用戶輸入
 def user_input(self, item):
 try:
  item = int(item)
 except:
  pass
 # 增加信息
 if item == 1:
  self.add_info()
 # 刪除信息
 elif item == 2:
  find = input('請輸入刪除的學(xué)號:')
  self.del_info(find=find)
 # 修改信息
 elif item == 3:
  self.modify_info()
 # 查找信息
 elif item == 4:
  self.search_info()
 # 顯示信息
 elif item == 5:
  self.display_info()
 # 信息排序
 elif item == 6:
  self.rank_info()
 # 退出程序 保存數(shù)據(jù)
 elif item == 0:
  with open('database.txt', 'w') as f:
  self.point = self.head
  while self.point.next:
   self.point = self.point.next
   f.writelines('{}\n'.format(self.point.data))
  exit()
 else:
  print('請輸入正確的數(shù)字')

 # id 保證互異性
 def unique_id(self, std_id):
 self.point = self.head
 while self.point.next:
  self.point = self.point.next
  if self.point.data['id'] == std_id:
  return False
 return True

 # 增加信息
 def add_info(self):
 # id 不能重復(fù)
 # 成績不能超出范圍
 name = input('姓名:')
 std_id = input('學(xué)生id:')
 while not self.unique_id(std_id=std_id):
  print('id重復(fù)')
  std_id = input('學(xué)生id:')
 grade = input('學(xué)生成績:')
 if eval(grade) < 0 or eval(grade) > 100:
  print('超出范圍')
  grade = input('學(xué)生成績:')
 print(name, std_id, grade)
 print('請確認(rèn)無誤后保存')
 choice = input('y/n')
 items = ['y', 'yes', 'Y', 'Yes']
 if choice in items:
  print(choice)
  data = {'id': std_id, 'name': name, 'grade': grade}
  self.append(data)

 # 刪除信息
 def del_info(self, find):
 print('請確認(rèn)無誤后保存')
 choice = input('y/n')
 items = ['y', 'yes', 'Y', 'Yes']
 if choice in items:
  if not self.head.next:
  print('鏈表為空')
  return None
  self.point = self.head
  while self.point.next.data['id'] != find:
  self.point = self.point.next
  pointer = self.point.next
  self.point.next = self.point.next.next
  del pointer

 # 序列逆序
 def reverse(self):
 local_list = StudentControlSystem()
 self.point = self.head
 count = 0
 while self.point.next:
  count += 1
  self.point = self.point.next
  data = self.point.data
  local_list.insert_after_head(data)
 return local_list

 # 序列排序
 def sort(self, item):
 length = self.get_size()
 i, j = 0, 0
 flag = 1
 while i < length:
  self.point = self.head.next
  while j < length - i - 1:
  if int(self.point.data[item]) > int(self.point.next.data[item]):
   # self.point.data, self.point.next.data =
   # self.point.next.data, self.point.data
   temp = self.point.data
   self.point.data = self.point.next.data
   self.point.next.data = temp
  self.point = self.point.next
  j += 1
  flag = 0
  if flag:
  break
  i += 1
  j = 0

 # 修改信息
 def modify_info(self):
 find = input('輸入需要修改的學(xué)生的id:')
 if not self.head.next:
  print('鏈表為空')
  return None
 self.point = self.head
 while str(self.point.next.data['id']) != find:
  self.point = self.point.next
  if self.point.next is None:
  print('沒有找到該元素')
  return None
 name = input('姓名:')
 grade = input('學(xué)生成績:')
 self.point.next.data['name'] = name
 self.point.next.data['grade'] = grade

 # 搜索信息
 def search_info(self):
 find = input('輸入需要查找的學(xué)生的id:')
 if not self.head.next:
  print('鏈表為空')
  return None
 self.point = self.head
 while str(self.point.next.data['id']) != find:
  self.point = self.point.next
  if self.point.next is None:
  print('沒有找到該元素')
  return None
 data = self.point.next.data
 print('ID 姓名 成績')
 print('{} {} {}'.format(data['id'], data['name'], data['grade']))

 # 信息排序
 def rank_info(self):
 choice = input('1.成績排序 2.學(xué)號排序:')
 order = input('1.升序 2.降序:')
 if choice == '1':
  item = 'grade'
 elif choice == '2':
  item = 'id'
 else:
  return None
 self.sort(item=item)
 if order == '2':
  temp = self.reverse()
  temp.display_info()
  return None
 self.display_info()

 # 顯示信息
 def display_info(self):
 self.point = self.head
 print('ID 姓名 成績')
 while self.point.next:
  self.point = self.point.next
  data = self.point.data
  print('{} {} {}'.format(data['id'], data['name'], data['grade']))
 print('')


def main():
 SCS = StudentControlSystem()
 try:
 with open('database.txt', 'r') as f:
  for data in f.readlines():
  SCS.append(eval(data))
 except:
 with open('database.txt', 'w') as f:
  pass

 while True:
 SCS.print_menu()
 item = input('請輸入你的選擇:')
 SCS.user_input(item)


if __name__ == "__main__":
 main()

運行后

然后就可以插入與查詢啦

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 關(guān)于pyqtSignal的基本使用

    關(guān)于pyqtSignal的基本使用

    這篇文章主要介紹了關(guān)于pyqtSignal的基本使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Odoo中如何生成唯一不重復(fù)的序列號詳解

    Odoo中如何生成唯一不重復(fù)的序列號詳解

    這篇文章主要給大家介紹了關(guān)于Odoo中如何生成唯一不重復(fù)的序列號的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-02-02
  • pytorch 中的dim的作用范圍詳解

    pytorch 中的dim的作用范圍詳解

    ptorch中的dim類似于numpy縱的axis,這篇文章給大家介紹pytorch 中的dim的作用范圍,不同的運算, dim 的作用域都是一樣的思想,本文給大家介紹的非常詳細,需要的朋友參考下吧
    2023-12-12
  • python 解決動態(tài)的定義變量名,并給其賦值的方法(大數(shù)據(jù)處理)

    python 解決動態(tài)的定義變量名,并給其賦值的方法(大數(shù)據(jù)處理)

    今天小編就為大家分享一篇python 解決動態(tài)的定義變量名,并給其賦值的方法(大數(shù)據(jù)處理),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • Python 實現(xiàn)RSA加解密文本文件

    Python 實現(xiàn)RSA加解密文本文件

    這篇文章主要介紹了Python 實現(xiàn)RSA加解密文本文件的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-12-12
  • Python中逗號轉(zhuǎn)為空格的三種方法

    Python中逗號轉(zhuǎn)為空格的三種方法

    本文介紹了Python中將逗號轉(zhuǎn)換為空格的三種方法,包含使用replace函數(shù)、使用split函數(shù)、使用正則表達式,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • Flask實現(xiàn)異步執(zhí)行任務(wù)

    Flask實現(xiàn)異步執(zhí)行任務(wù)

    在一些開發(fā)中,可能會遇到需要長時間處理的任務(wù),此時就需要使用異步的方式來實現(xiàn),本文就介紹了Flask實現(xiàn)異步執(zhí)行任務(wù)的方法,感興趣的可以了解一下
    2021-05-05
  • Python將一個Excel拆分為多個Excel

    Python將一個Excel拆分為多個Excel

    這篇文章主要為大家詳細介紹了Python將一個Excel拆分為多個Excel,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • PyQt5使用QtDesigner實現(xiàn)多界面切換程序的全過程

    PyQt5使用QtDesigner實現(xiàn)多界面切換程序的全過程

    Pyqt5是Python中一個可視化超級好用的庫,下面這篇文章主要給大家介紹了關(guān)于PyQt5使用QtDesigner實現(xiàn)多界面切換程序的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2023-06-06
  • Python中的函數(shù)參數(shù)類型檢查

    Python中的函數(shù)參數(shù)類型檢查

    這篇文章主要介紹了Python中的函數(shù)參數(shù)類型檢查,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12

最新評論