其他分享
首页 > 其他分享> > 实验五

实验五

作者:互联网

实验任务5:自定义模块及模块导入编程   一:把类StudentDoc保存到模块student.py中

'''student.py'''

class StudentDoc:
'''学生档案管理'''
def __init__(self,students_number,studens_name,major,python_score):
self._students_number=students_number
self._studens_name=studens_name
self._major=major
self._python_score=python_score

def score(self):
return print(f"{self._studens_name}的python课程分数{self._python_score}",end="\n")

def modify_score(self,sore):
self._python_score=sore

def info(self):
print(f"学号:{self._students_number}")
print(f"姓名:{self._studens_name}")
print(f"专业:{self._major}")

#测试类
def main():
a1=StudentDoc("202013170066","Bob","生态学",90)
a2=StudentDoc("202013170052","Mary","生态学",85)

a1.info()
a2.info()

a1.score()
a2.score()

if __name__ == '__main__':
print('模块信息: ', __doc__)
print('StudentDoc类信息: ', StudentDoc.__doc__)

main()

二:编写Python文件task5.py, 导入模块student。创建学生对象s1, s2,调用方法测试学生信息打印、 修改课程分数、打印课程分数等操作。

import student#导入模块

s1=student.StudentDoc("202013170066","Bob","生态学",90)
s2=student.StudentDoc("202013170052","Mary","生态学",85)

s1.modify_score(75)
s1.info()
s1.score()

s2.modify_score(60)
s2.info()
s2.score()

标签:__,python,self,._,score,实验,StudentDoc
来源: https://www.cnblogs.com/sdyW/p/14836709.html