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. yaml中使用harbor

    1.在harbor的ui界面上注册一个账号 姓名:zihao 全名:zhuzihao 密码:Zihao@5tgb 邮箱:15613691030@163.com 2.在需要下载镜像的机器上,同样需要修改 ...

  2. 使用Docker在本地启动3个MySQL镜像

    首先执行 sudo docker pull mysql 命令下载mysql官方镜像: zifeiy@zifeiy-PC:~$ sudo docker pull mysql Using default ...

  3. angular2 ng-if

    ng-if <td ><div class="td-li" > <a (click)="open(i)" class=" ...

  4. 前端研究CSS之文字与特殊符号元素结合的浏览器兼容性总结

    页面布局里总是会有类似 “文字 | 文字” 的设计样式,不同的浏览器存在严重偏差. 有兼容问题就要解决,下面总结了3种解决方案,分享给大家: 一.系统默认的样式 1.元素换行的段落 <div c ...

  5. [Google] 9717 取数对弈

    我写的Python代码: class Solution(object): def getNumberGame(self, n, nums): m = len(nums) dp = [[0] * m f ...

  6. composer安装扩展包异常

    我是tp5.1下,用composer安装扩展包,在命令行运行,无任何不反应,不下载也不报错,这时,我们先ctrl+c退出执行的命令,然后在tp5.1根目录下,找到composer.json文件,并用编 ...

  7. 使用jetpack 4.2.2对jetson tx2进行刷机

    一.前言 加班加点几天今天终于成功刷机,记录一下成功的一些过程,以方便同样卡住的朋友参考. 延续官网教程[1]中对设备的叫法,pc机称为host,tx2称为target. 二.过程 1. host相关 ...

  8. 修改Linux服务器中的MySql密码

    1.可以直接在数据库中修改,因为知道root密码,所以直接登录 mysql -uroot -p 2.查看一下数据库,修改root密码需要使用如下图所示的mysql数据库 3.通过use mysql指明 ...

  9. ajax后台跳转无效的原因

    Ajax只是利用脚本访问对应url获取数据而已,不能做除了获取返回数据以外的其它动作了.所以浏览器端是不会发起重定向的. 1)正常的http url请求,只有浏览器和服务器两个参与者.浏览器端发起一个 ...

  10. PAT甲级题分类汇编——杂项

    本文为PAT甲级分类汇编系列文章. 集合.散列.数学.算法,这几类的题目都比较少,放到一起讲. 题号 标题 分数 大意 类型 1063 Set Similarity 25 集合相似度 集合 1067 ...