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 Student 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 } } ) student1.calc_marks('nwu112')
student1.calc_marks('nwu113')

最新文章

  1. kali linux下的arp攻击
  2. java的IO操作之--RandomAccessFile
  3. FileSystemWatcher触发多次Change事件的解决办法 .
  4. 得到RTP包中的timestamp
  5. SUN-LDAP6.3_RHEL 5.0-卸载LDAP
  6. visual studio2013负载测试简单问题记录
  7. 【译】在ASP.NET中创建PDF-iTextSharp起步
  8. java 用hmac-sha1进行签名
  9. RabbitMQ中声明交换器,队列时的,autoDelete=true自动删除的条件
  10. asp.net mvc5中使用Swagger 自动生成WebApi文档笔记
  11. python学习笔记----正则表达式
  12. free mybtis plugin
  13. H5拖动火狐自动打开新标签
  14. LeetCode(52):N皇后 II
  15. Java编程的逻辑 (15) - 初识继承和多态
  16. faker php测试数据库生成
  17. 洛咕P4542 [ZJOI2011]营救皮卡丘
  18. ftpclient 编码备忘
  19. python网络编程详解
  20. Web前端开发笔试&面试_02(others)

热门文章

  1. 深层对象转深层数组(重点:先把对象转数组,直接for in 遍历对象不太可行)
  2. APP排查内存泄漏最简单和直观的方法
  3. android基础---->传感器的使用
  4. Linux(Ubuntu)下的OpenGl的环境安装, 在qt程序中使用opengl库
  5. linux编程 新建一个进程的方法
  6. ubuntu gcc 安装 使用
  7. LeetCode 459. 重复的子字符串(Repeated Substring Pattern)
  8. python 之 并发编程(非阻塞IO模型、I/O多路复用、socketserver的使用)
  9. 机器学习-HMM隐马尔可夫模型-笔记
  10. AS3.0 位图(BMP)解析类