Python语言程序设计:Lab5

Python语言程序设计:Lab5,第1张

概述Programming Create a Class Student which should have the following information: Parameters passed to __init__ when an instance of the class is created: self p_surname - a string p_given_name - a strin Programming

Create a Class Student which should have the following information:
Parameters passed to __init__ when an instance of the class is created:
self
p_surname - a string
p_given_name - a string
p_ID - an integer
p_results - a List - see below for the expected format
These will then be used to set the following instance variables:
self.surname
self.given_name
self.ID
self._results (underscore ‘_‘ means it is hIDden from the user)
There will also be a method:
calc_marks()
This method will take as argument a module code e.g. ‘nwu112‘ and it will calculate the final mark for
the student for that particular module according to the assumption:
20% project 1
20% project 2
10% multiple choice test
50% final exam
An instance of a student will be created like this:

student1 = Student( Sutcliffe,Richard,2017123456,{ nwu112: { project1: 60,project2: 65,mcq_test: 70,final_exam: 80 },nwu113: { project1: 68,project2: 57,mcq_test: 60,final_exam: 70 } } )

 

So,the results consist of a dictionary where the key is ‘nwu112‘ or ‘nwu113‘ and the value in each case
is another dictionary containing the different marks.
When you have your Class written,create a couple of instances of the class; for each one,invent a
surname,given name,ID and results List. etc.
Finally,run calc_marks() on your student objects to find out their final mark for a module. In other
words,you will do:
student1.calc_marks( ‘nwu112‘ )
Your method will be in the Student Class and so will have access to student._results . So in
calc_marks() you will be able to do:
student._results[ ‘nwu112‘ ]
to get the results for the module nwu112. For the project1 marks for nwu112 you will be able to do:
student._results[ ‘nwu112‘ ] [ ‘project1‘ ]
and the value of that,assuming the above data,is the integer 60. You can use these numbers to
calculate the overall result for a module.

 

"""Student.py""""""Student类"""class Student:    def __init__(self,p_surname,p_given_name,p_ID,p_results):        self.surname=p_surname        self.given_name=p_given_name        self.ID=p_ID        self._results=p_results    def calc_marks(self,subject):        marks=self._results[subject]        result=marks[project1]*0.2+marks[project2]*0.2+marks[mcq_test]*0.1+marks[final_exam]*0.5        print("The final mark of "+self.surname+" about subject "+subject+" is "+str(result))        return result
"""test.py"""from Student import Studentstudent1 = Student( Sutcliffe,final_exam: 70 } } )student1.calc_marks(nwu112)student1.calc_marks(nwu113)
总结

以上是内存溢出为你收集整理的Python语言程序设计:Lab5全部内容,希望文章能够帮你解决Python语言程序设计:Lab5所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1190891.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存