You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

def input_info():
infile_info = open('infile.txt', 'a') # 以追加的方式向文件中写入数据,如果文件不存在就创建一个文件
flag = 'y'
# 向文件中录入课程信息,每一个课程的信息单独占一行
while flag == 'y' or flag == 'Y':
stu_id = input("请输入课程编号:")
stu_name = input("请输入课程名称:")
stu_score_eng = input("请输入课程性质:")
stu_score_py = input("请输入总学时:")
stu_score_hour = input("请输入授课学时:")
stu_score_shour = input("请输入实验学时:")
stu_score_credit = input("请输入学分:")
stu_score_term = input("开课学期:")
stu_info = stu_id + '\t\t\t' + stu_name + '\t\t\t' + stu_score_eng + '\t\t\t' + stu_score_py + '\t\t\t' + stu_score_hour +'\t\t\t' +stu_score_shour+ '\t\t\t' +stu_score_credit +'\t\t\t' +stu_score_term +'\t\t\t'+'\n'
infile_info.write(stu_info)
flag = input("是否继续添加学生信息y/n")
print("信息录入完毕!!!")
infile_info.close()
# 查询课程信息
# 查询时分为按课程号和按课性质查找两种
def find_info():
flag = 'y'
while flag == 'y' or flag == 'Y':
n = 0
m = 0 # 定义mn是为了用作判断文件中是否有此课程的标记
findfile_info = open('infile.txt', 'r') # 以可读方式打开文件
line_info = findfile_info.readlines()
find_nid = input("按课程号查找请输入1按课程性质查找请输入2") # 查询时分为按课程号和按课性质查找两种
if find_nid == '1':
find_id = input('请输入课程号:')
for line in line_info:
if find_id in line:
print(line)
n = n + 1
if n == 0:
print("没有查询到课程信息,无数据显示!!!")
if find_nid == '2':
find_eng = input('请输入课程性质:')
for line in line_info:
if find_eng in line:
print(line)
m = m + 1
if m == 0:
print("没有查询到课程信息,无数据显示!!!")
findfile_info.close()
flag = input("是否继续查询课程信息y/n")
#学生选修课程
def choos_sourse():
infile_info = open('student.txt', 'a')
findfiles_info = open('infile.txt', 'r') # 以可读方式打开文件
lines_info = findfiles_info.readlines()
student_name=input('输入你的姓名:')
choos_id = input('请输入课程名(若无此课程,自动退出!)')
for line in lines_info:
if choos_id in line:
print('选课成功!')
choos_info = student_name + '\t\t\t' + choos_id + '\n'
infile_info.write(choos_info)
# 统计课程总数
def sum_info():
sumfile_info = open('infile.txt', 'r')
line_info = sumfile_info.readlines()
sum_stu = len(line_info) # 写出列表中的元素个数
print("一共有{0}门课程。".format(sum_stu))
sumfile_info.close()
# 显示课程信息
def show_info():
print("课程编号", end='\t\t')
print("课程名称", end='\t\t')
print("课程性质", end='\t\t')
print("总学时", end='\t\t')
print("授课学时", end='\t\t')
print("实验学时", end='\t\t')
print("学分", end='\t\t')
print("开课学期", end='\t\t')
print('\n')
showfile_info = open('infile.txt', 'r')
line_info = showfile_info.readlines()
for line in line_info: # 遍历列表,输出各个元素
print(line)
showfile_info.close()
#显示选课信息
def show_chooses():
print("姓名", end='\t\t')
print("已选课程", end='\t\t')
print('\n')
showfile_info = open('student.txt', 'r')
line_info = showfile_info.readlines()
for line in line_info: # 遍历列表,输出各个元素
print(line)
showfile_info.close()
def show_choose():
print("==========================学生选修课程系统==========================")
print()
print("-----------------------------功能菜单------------------------------")
print()
print(" 1.录入选课信息")
print(" 2.查找课程信息")
print(" 3.显示选修课程")
print(" 4.学生选修课程")
print(" 5.统计课程总数")
print(" 6.学生选课信息")
print(" 0.退出选修课程系统")
print()
print("------------------------------------------------------------------")
def main():
show_choose()
choose_menu = input("请选择:")
while choose_menu != '0':
if choose_menu == '1':
input_info()
if choose_menu == '2':
find_info()
if choose_menu == '3':
show_info()
if choose_menu == '4':
choos_sourse()
if choose_menu == '5':
sum_info()
if choose_menu == '6':
show_chooses()
choose_menu = input("请选择:")
print("欢迎您再次使用!!!")
main()