Python语言程序设计:Lab5
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的更多相关文章
- 【任务】Python语言程序设计.MOOC学习
[博客导航] [Python导航] 任务 18年11月29日开始,通过9周时间跨度,投入约50小时时间,在19年1月25日之前,完成中国大学MOOC平台上的<Python语言程序设计>课程 ...
- 全国计算机等级考试二级Python语言程序设计考试大纲
全国计算机等级考试二级Python语言程序设计考试大纲(2018年版) 基本要求 掌握Python语言的基本语法规则. 掌握不少于2个基本的Python标准库. 掌握不少于2个Python第三方库,掌 ...
- Python语言程序设计之二--用turtle库画围棋棋盘和正、余弦函数图形
这篇笔记依然是在做<Python语言程序设计>第5章循环的习题.其中有两类问题需要记录下来. 第一是如何画围棋棋盘.围棋棋盘共有19纵19横.其中,位于(0,0)的星位叫天元,其余8个星位 ...
- Python语言程序设计之一--for循环中累加变量是否要清零
最近学到了Pyhton中循环这一章.之前也断断续续学过,但都只是到了函数这一章就停下来了,写过的代码虽然保存了下来,但是当时的思路和总结都没有记录下来,很可惜.这次我开通了博客,就是要把这些珍贵的学习 ...
- Python语言程序设计之三--列表List常见操作和错误总结
最近在学习列表,在这里卡住了很久,主要是课后习题太多,而且难度也不小.像我看的这本<Python语言程序设计>--梁勇著,列表和多维列表两章课后习题就有93道之多.我的天!但是题目出的非常 ...
- Python语言程序设计(1)--实例1和基本知识点
记录慕课大学课程<Python语言程序设计>的学习历程. 实例1:温度转换 #温度转换TempStr = input("请输入带有符号的温度值:") #TempStr是 ...
- Python语言程序设计学习 之 了解Python
Python简介 Python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. Python是纯粹的自由软件,源代 ...
- 【学习笔记】PYTHON语言程序设计(北理工 嵩天)
1 Python基本语法元素 1.1 程序设计基本方法 计算机发展历史上最重要的预测法则 摩尔定律:单位面积集成电路上可容纳晶体管数量约2年翻倍 cpu/gpu.内存.硬盘.电子产品价格等都遵 ...
- Python语言程序设计(3)--实例2-python蟒蛇绘制-turtle库
1. 2. 3.了解turtle库 Turtle,也叫海龟渲染器,使用Turtle库画图也叫海龟作图.Turtle库是Python语言中一个很流行的绘制图像的函数库.海龟渲染器,和各种三维软件都有着良 ...
- 全国计算机等级考试二级教程2019年版——Python语言程序设计参考答案
第二章 Python语言基本语法元素 一.选择题C B B C A D B A D B二.编程题1.获得用户输入的一个整数N,计算并输出N的32次方.在这里插入图片描述2.获得用户输入的一段文字,将这 ...
随机推荐
- 11点睛Spring4.1-Property Editor
11.1 Propert Editor property editor是JavaBeans API的一项特性,用来字符和属性值之间的互相转换(如2014-03-02和Date类型的互相转换) spri ...
- 【ARTS】01_44_左耳听风-201900909~201900915
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- 19-js策略模式
var PriceStrategy = function() { var stragtegy = { return30: function(price) { return +price + parse ...
- httpsqs消息队安装
HTTPSQS(HTTP Simple Queue Service)是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,使用 Tokyo Cabinet 的 B+Tree Key ...
- Eclipse+TestNG搭建接口自动化测试框架
一.环境安装 1.前提 安装好jdk 配置好Java环境变量 安装Eclips 这些网上都有,就不再详细介绍. 资源分享链接:http://pan.baidu.com/s/1v9Fw6 2.安装Tes ...
- jQuery (js 和 jQuery 的区别)
js 和 jQuery 的区别 主要体现在Dom操作 (jq代表我找到的元素对象)找元素: js:document.get... jquery: $(选择器)设定:jq 是jquery对 ...
- git的基本使用流程
1. 在远端创建代码仓库 2. 拉取到本地 git clone $(path) #其中,path包括git路径或者https路径,可通过实际情况进行拉取.另外,可通过-b参数指定拉取的分支,默认拉取m ...
- Linux DNS 服务器配置与管理
一.环境介绍: 运行软件:VMware Workstation Pro 14 系统环境:CentOS-7-x86_64-1810 二.操作配置: 1.基础知识简介 (1)域名空间 域和域名: DNS树 ...
- LeetCode 168. Excel表列名称(Excel Sheet Column Title)
168. Excel表列名称 168. Excel Sheet Column Title 题目描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. LeetCode168. Excel S ...
- 多线程(11) — NIO
Java NIO是new IO的简称,是一种可以替代Java IO的一套新的IO机制.它提供了一套不同于Java标准IO的操作机制,严格来说,NIO与并发并无直接关系,但是使用NIO技术可以大大提高线 ...