前言
嗨嘍!大家好呀,這里是魔王~**
大家都是畢設出來的畢設魂,做畢設的時候你一定會知道這個案例,
接下來我們就來實現~!·
開發(fā)環(huán)境:
- Python 3.8
- Pycharm 2021.2
涉及知識點:
- Python基礎語法
- 基本的數據類型與結構
- 基本的邏輯控制語句
- 實戰(zhàn)小項目
代碼
import requests
import random
import time
import parsel
msg = """**************************************************
歡迎使用【學生信息管理系統(tǒng)】V1.0
請選擇你想要進行的操作
1. 新建學生信息
2. 顯示全部信息
3. 查詢學生信息
4. 刪除學生信息
5. 修改學生信息
0. 退出系統(tǒng)
**************************************************"""
# 學生信息 用列表保存 并且 里面字典數據類型
student_info = [
{'姓名': '木子', '語文': 60, '數學': 60, '英語': 60, '總分': 180},
{'姓名': '巳月', '語文': 60, '數學': 60, '英語': 60, '總分': 180},
{'姓名': '落落', '語文': 60, '數學': 60, '英語': 60, '總分': 180},
]
# == 是什么意思 比較運算符是否相等 不等于 != = 又是什么意思 >>> 賦值
account = input('請輸入你的賬號: ')
password = input('請輸入你的密碼: ')
if account == 'ziyouzhenshuai' and password == 'zhendeshuai':
print('密碼正確, 歡迎使用')
while True: # 當一直為真的時候 就運行一直運行下面的代碼 死循環(huán)...
print(msg) # 輸出函數 打印
word = input('請輸入你想要進行的操作: ')
if word == '1':
print('新建學生信息')
# input輸入函數, 輸入內容, 返回數據類型 字符串, 字符串和字符串拼接使用 +
name = input('請輸入學生姓名: ')
chinese = input('請輸入語文成績: ')
math = input('請輸入數學成績: ')
english = input('請輸入英語成績: ') # 100+100+100 >>> 100100100
sum = int(chinese) + int(math) + int(english) # 總分
dit = {
'姓名': name,
'語文': chinese,
'數學': math,
'英語': english,
'總分': sum,
}
student_info.append(dit)
elif word == '2':
print('顯示全部信息')
print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
for student in student_info:
# student['姓名'] 根據鍵值對提取數據
print(
student['姓名'] + '\t\t' +
str(student['語文']) + '\t\t\t' +
str(student['數學']) + '\t\t\t' +
str(student['英語']) + '\t\t\t' +
str(student['總分']) + '\t\t\t'
)
elif word == '3':
print('查詢學生信息')
name = input('請輸入你想要查詢學生的姓名: ')
# print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
for student in student_info: # 從學生檔案里一個一個拿出來 for循環(huán)遍歷
# 把列表里面的元素 一個一個提取出來
if name == student['姓名']: # 對比一下 輸入名字 是否在里面
print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
print(
student['姓名'] + '\t\t' +
str(student['語文']) + '\t\t\t' +
str(student['數學']) + '\t\t\t' +
str(student['英語']) + '\t\t\t' +
str(student['總分']) + '\t\t\t'
)
break
else:
print('查無此人, 請確認信息再查詢')
elif word == '4':
print('刪除學生信息')
name = input('請輸入你想要刪除學生的姓名: ')
for student in student_info: # 從學生檔案里一個一個拿出來 for循環(huán)遍歷
# 把列表里面的元素 一個一個提取出來
if name == student['姓名']: # 對比一下 輸入名字 是否在里面
print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
print(
student['姓名'] + '\t\t' +
str(student['語文']) + '\t\t\t' +
str(student['數學']) + '\t\t\t' +
str(student['英語']) + '\t\t\t' +
str(student['總分']) + '\t\t\t'
)
result = input('是否確認要刪除(y/n): ')
if result == 'y':
# 列表如何刪除元素
student_info.remove(student) # 指定元素刪除
elif result == 'n':
continue
break
else:
print('查無此人, 請確認信息再刪除')
elif word == '5':
print('修改學生信息')
name = input('請輸入你想要修改學生的姓名: ')
for student in student_info: # 從學生檔案里一個一個拿出來 for循環(huán)遍歷
# 把列表里面的元素 一個一個提取出來
if name == student['姓名']: # 對比一下 輸入名字 是否在里面
print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
print(
student['姓名'] + '\t\t' +
str(student['語文']) + '\t\t\t' +
str(student['數學']) + '\t\t\t' +
str(student['英語']) + '\t\t\t' +
str(student['總分']) + '\t\t\t'
)
result = input('是否確認要修改(y/n): ')
if result == 'y':
name = input('請輸入學生姓名: ')
chinese = input('請輸入語文成績: ')
math = input('請輸入數學成績: ')
english = input('請輸入英語成績: ') # 100+100+100 >>> 100100100
sum = int(chinese) + int(math) + int(english) # 總分
student['姓名'] = name
student['語文'] = chinese
student['數學'] = math
student['英語'] = english
student['總分'] = sum
# dit = {
# '姓名': name,
# '語文': chinese,
# '數學': math,
# '英語': english,
# '總分': sum,
# }
# student_info.append(dit)
elif result == 'n':
continue
break
else:
print('查無此人, 請確認信息再修改')
elif word == '0':
print('退出系統(tǒng), 歡迎下次使用~')
break
elif account == 'dxshh' and password == 'zhendehao':
while True:
name = input('請輸入你想要查詢學生的姓名(輸入0即可退出): ')
# print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
if name == '0':
break
for student in student_info: # 從學生檔案里一個一個拿出來 for循環(huán)遍歷
# 把列表里面的元素 一個一個提取出來
if name == student['姓名']: # 對比一下 輸入名字 是否在里面
print('姓名\t\t語文\t\t數學\t\t英語\t\t總分')
print(
student['姓名'] + '\t\t' +
str(student['語文']) + '\t\t\t' +
str(student['數學']) + '\t\t\t' +
str(student['英語']) + '\t\t\t' +
str(student['總分']) + '\t\t\t'
)
break
else:
print('查無此人, 請確認信息再查詢')
else:
print('賬號或者密碼不正確')
尾語
好了,我的這篇文章寫到這里就結束啦!
有更多建議或問題可以評論區(qū)或私信我哦!一起加油努力叭(? ?_?)?
喜歡就關注一下博主,或點贊收藏評論一下我的文章叭?。。?/p>