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')

Python语言程序设计:Lab5的更多相关文章

  1. 【任务】Python语言程序设计.MOOC学习

    [博客导航] [Python导航] 任务 18年11月29日开始,通过9周时间跨度,投入约50小时时间,在19年1月25日之前,完成中国大学MOOC平台上的<Python语言程序设计>课程 ...

  2. 全国计算机等级考试二级Python语言程序设计考试大纲

    全国计算机等级考试二级Python语言程序设计考试大纲(2018年版) 基本要求 掌握Python语言的基本语法规则. 掌握不少于2个基本的Python标准库. 掌握不少于2个Python第三方库,掌 ...

  3. Python语言程序设计之二--用turtle库画围棋棋盘和正、余弦函数图形

    这篇笔记依然是在做<Python语言程序设计>第5章循环的习题.其中有两类问题需要记录下来. 第一是如何画围棋棋盘.围棋棋盘共有19纵19横.其中,位于(0,0)的星位叫天元,其余8个星位 ...

  4. Python语言程序设计之一--for循环中累加变量是否要清零

    最近学到了Pyhton中循环这一章.之前也断断续续学过,但都只是到了函数这一章就停下来了,写过的代码虽然保存了下来,但是当时的思路和总结都没有记录下来,很可惜.这次我开通了博客,就是要把这些珍贵的学习 ...

  5. Python语言程序设计之三--列表List常见操作和错误总结

    最近在学习列表,在这里卡住了很久,主要是课后习题太多,而且难度也不小.像我看的这本<Python语言程序设计>--梁勇著,列表和多维列表两章课后习题就有93道之多.我的天!但是题目出的非常 ...

  6. Python语言程序设计(1)--实例1和基本知识点

    记录慕课大学课程<Python语言程序设计>的学习历程. 实例1:温度转换 #温度转换TempStr = input("请输入带有符号的温度值:") #TempStr是 ...

  7. Python语言程序设计学习 之 了解Python

    Python简介 Python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. Python是纯粹的自由软件,源代 ...

  8. 【学习笔记】PYTHON语言程序设计(北理工 嵩天)

    1 Python基本语法元素 1.1 程序设计基本方法 计算机发展历史上最重要的预测法则     摩尔定律:单位面积集成电路上可容纳晶体管数量约2年翻倍 cpu/gpu.内存.硬盘.电子产品价格等都遵 ...

  9. Python语言程序设计(3)--实例2-python蟒蛇绘制-turtle库

    1. 2. 3.了解turtle库 Turtle,也叫海龟渲染器,使用Turtle库画图也叫海龟作图.Turtle库是Python语言中一个很流行的绘制图像的函数库.海龟渲染器,和各种三维软件都有着良 ...

  10. 全国计算机等级考试二级教程2019年版——Python语言程序设计参考答案

    第二章 Python语言基本语法元素 一.选择题C B B C A D B A D B二.编程题1.获得用户输入的一个整数N,计算并输出N的32次方.在这里插入图片描述2.获得用户输入的一段文字,将这 ...

随机推荐

  1. Swift4.0复习类

    1.类的属性: 2.类的方法: 3.类作为引用类型: “Swift新增了一对操作符 === 与 !== 用于判定同一个类的两个对象引用是否指向同一对象实例.” 摘录来自: “大话Swift 4.0”. ...

  2. HDU3853 LOOPS 期望DP基础题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题目大意(只是大意,名字什么的可能和原题描述不一样~): 爱丽丝与华容道 题目描述 爱丽丝是一个 ...

  3. PHP实现单点登录最简单的方法

    PHP实现单点登录最简单的方法 用户在A登录 存入登录状态 登录B站(A的识别要传入B) 获取A的登录状态

  4. mysql数据库表的查询

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  5. [转帖]Kubernetes - nginx-ingress 配置跳坑指南

    Kubernetes - nginx-ingress 配置跳坑指南 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https:// ...

  6. C之推栈溢出原因

    https://blog.csdn.net/weixin_36194037/article/details/78871468

  7. 长乐培训Day8

    T1 远征 题目 [题目描述] 寒枫将军将要带领他的部队去圣雪山消灭那里的冰龙.部队分成了若干个小队,属于同一个小队的人兵种相同. 寒枫将军有着杰出的指挥能力,在战斗的时候,寒枫将军能够让所有相同兵种 ...

  8. 以php中的算数运算符操作(整型,浮点型,字符串型,布尔型,空类型)数据

    // 环境 // // php版本 // PHP 7.0.33-0+deb9u1 (cli) (built: Dec 7 2018 11:36:49) ( NTS ) // Copyright (c) ...

  9. python 之 数据库(内置函数、流程控制、索引)

    10.17 内置函数 强调:mysql内置的函数只能在sql语句中使用 #数学函数 round(x,y) #返回参数x的四舍五入的有y位小数的值 rand() #返回0到1内的随机值,可以通过提供一个 ...

  10. C++利用权重方法将二进制正数转换为十进制数

    #include <iostream> #include <Windows.h> #include <string> using namespace std; in ...