Quiz 15: Object-Oriented Programming | Python for Everybody 配套练习_解题记录

news2024/9/23 3:27:40

文章目录

  • Python for Everybody
    • 课程简介
  • Quiz 15: Object-Oriented Programming
    • 单选题(1-11)
    • Multiple instances


Python for Everybody


课程简介

Python for Everybody 零基础程序设计(Python 入门)

  • This course aims to teach everyone the basics of programming computers using Python. 本课程旨在向所有人传授使用 Python 进行计算机编程的基础知识。
  • We cover the basics of how one constructs a program from a series of simple instructions in Python. 我们介绍了如何通过 Python 中的一系列简单指令构建程序的基础知识。
  • The course has no pre-requisites and avoids all but the simplest mathematics. Anyone with moderate computer experience should be able to master the materials in this course. 该课程没有任何先决条件,除了最简单的数学之外,避免了所有内容。任何具有中等计算机经验的人都应该能够掌握本课程中的材料。
  • This course will cover Chapters 1-5 of the textbook “Python for Everybody”. Once a student completes this course, they will be ready to take more advanced programming courses. 本课程将涵盖《Python for Everyday》教科书的第 1-5 章。学生完成本课程后,他们将准备好学习更高级的编程课程。
  • This course covers Python 3.

在这里插入图片描述

coursera

Python for Everybody 零基础程序设计(Python 入门)

Charles Russell Severance
Clinical Professor

在这里插入图片描述

个人主页
Twitter

在这里插入图片描述

University of Michigan


课程资源

coursera原版课程视频
coursera原版视频-中英文精校字幕-B站
Dr. Chuck官方翻录版视频-机器翻译字幕-B站

PY4E-课程配套练习
Dr. Chuck Online - 系列课程开源官网



Quiz 15: Object-Oriented Programming

We do a quick look at how Python supports the Object-Oriented programming pattern.


单选题(1-11)

  1. Which came first, the instance or the class?
  • method
  • class
  • instance
  • function
  1. In Object Oriented Programming, what is another name for the attributes of an object?
  • portions
  • messages
  • fields
  • forms
  • methods
  1. Which of the following is NOT a good synonym for “class” in Python?
  • blueprint
  • template
  • pattern
  • direction
  1. What does this Python statement do if PartyAnimal is a class?
    zap = PartyAnimal()
  • Use the PartyAnimal template to make a new object and assign it to zap
  • Copy the value from the PartyAnimal variable to the variable zap
  • Subtract the value of the zap variable from the value in the PartyAnimal variable and put the difference in zap
  • Clear out all the data in the PartyAnimal variable and put the old values for the data in zap
  1. What is the syntax to look up the fullname attribute in an object stored in the variable colleen?
  • $colleen->fullname
  • c o l l e e n − > colleen-> colleen>fullname
  • $colleen::fullname
  • colleen.fullname
  • $colleen[“fullname”]
  1. Which of the following statements are used to indicate that class A will inherit all the features of class B?
  • class A(B):
  • A=B++;
  • class A extends B:
  • class A inherits B:
  • class A instanceOf B;
  1. How is “self” typically used in a Python method within a class?
  • The number of parameters to the method
  • To set the residual value in an expression where the method is used
  • To terminate a loop
  • To refer to the instance in which the method is being called
  1. What does the Python dir() function show when we pass an object into it as a parameter?
  • It shows the methods and attributes of an object
  • It shows the type of the object
  • It shows the parent class
  • It shows the number of parameters to the constructor
  1. Which of the following is rarely used in Object Oriented Programming?
  • Attribute
  • Inheritance
  • Destructor
  • Method
  • Constructor

Multiple instances

So far, we have defined a class, constructed a single object, used that object, and then thrown the object away. However, the real power in object-oriented programming happens when we construct multiple instances of our class.

When we construct multiple objects from our class, we might want to set up different initial values for each of the objects. We can pass data to the constructors to give each object a different initial value:

class PartyAnimal:
   x = 0
   name = ''
   def __init__(self, nam):
     self.name = nam
     print(self.name,'constructed')

   def party(self) :
     self.x = self.x + 1
     print(self.name,'party count',self.x)

s = PartyAnimal('Sally')
j = PartyAnimal('Jim')

s.party()
j.party()
s.party()

# Code: http://www.py4e.com/code3/party5.py

The constructor has both a self parameter that points to the object instance and additional parameters that are passed into the constructor as the object is constructed:

s = PartyAnimal('Sally')

Within the constructor, the second line copies the parameter (nam) that is passed into the name attribute within the object instance.

self.name = nam

The output of the program shows that each of the objects (s and j) contain their own independent copies of x and nam:

Sally constructed
Jim constructed
Sally party count 1
Jim party count 1
Sally party count 2

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/708100.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

qemu 源码编译 qemu-system-aarch64 的方法

前言 最近调试 RT-Thread bsp qemu-virt64-aarch64 时,遇到无法使用网络设备问题,最后确认是 当前 ubuntu 20.04 系统 使用 apt install 安装的 qemu qemu-system-aarch64 版本太低。 RT-Thread qemu-virt64-aarch64 里面的网络设备,需要较新…

回顾分类决策树相关知识并利用python实现

大家好,我是带我去滑雪! 决策树(Decision Tree)是一种基本的分类与回归方法,呈树形结构,在分类问题中,表示预计特征对实例进行分类的过程。它可以认为是if-then规则的集合,也可以认为…

多表-DDL以及DQL

多表DDL 个表之间也可能存在关系 存在在一对多和多对多和一对多的关系 一对多(外键) 在子表建一哥字段(列)和对应父表关联 父表是一,对应子表的多(一个部门对应多个员工,但一个员工只能归属一…

结构体和数据结构--从基本数据类型到抽象数据类型、结构体的定义

在冯-诺依曼体系结构中,程序代码和数据都是以二进制存储的,因此对计算机系统和硬件本身而言,数据类型的概念其实是不存在的。 在高级语言中,为了有效的组织数据,规范数据的使用,提高程序的可读性&#xff0…

使用Streamlit和Matplotlib创建交互式折线图

大家好,本文将介绍使用Streamlit和Matplotlib创建一个用户友好的数据可视化Web应用程序。该应用程序允许上传CSV文件,并为任何选定列生成折线图。 构建Streamlit应用程序 在本文中,我们将指导完成创建此应用程序的步骤。无论你是专家还是刚刚…

three.js利用点材质打造星空

最终效果如图: 一、THREE.BufferGeometry介绍 这里只是做个简单的介绍,详细的介绍大家可以看看THREE.BufferGeometry及其属性介绍 THREE.BufferGeometry是Three.js中的一个重要的类,用于管理和操作几何图形数据。它是对THREE.Geometry的一…

leetcode 226. 翻转二叉树

2023.7.1 这题依旧可以用层序遍历的思路来做。 在层序遍历的代码上将所有节点的左右节点进行互换即可实现二叉树的反转。 下面上代码&#xff1a; class Solution { public:TreeNode* invertTree(TreeNode* root) {queue<TreeNode*> que;if(root nullptr) return{};que…

gradio库中的Dropdown模块:创建交互式下拉菜单

❤️觉得内容不错的话&#xff0c;欢迎点赞收藏加关注&#x1f60a;&#x1f60a;&#x1f60a;&#xff0c;后续会继续输入更多优质内容❤️ &#x1f449;有问题欢迎大家加关注私戳或者评论&#xff08;包括但不限于NLP算法相关&#xff0c;linux学习相关&#xff0c;读研读博…

2020年全国硕士研究生入学统一考试管理类专业学位联考逻辑试题——纯享题目版

&#x1f3e0;个人主页&#xff1a;fo安方的博客✨ &#x1f482;个人简历&#xff1a;大家好&#xff0c;我是fo安方&#xff0c;考取过HCIE Cloud Computing、CCIE Security、CISP等证书。&#x1f433; &#x1f495;兴趣爱好&#xff1a;b站天天刷&#xff0c;题目常常看&a…

编译原理期末复习简记(更新中~)

注意&#xff1a;该复习简记只是针对我校期末该课程复习纲要进行的&#xff0c;仅供参考 第一章 引论 编译程序是什么&#xff1f; 编译程序是一个涉及分析和综合的复杂系统 编译程序组成 编译程序通常由以下内容组成 词法分析器 输入 组成源程序的字符串输出 记号/单词序列语法…

Jenkins+Gitlab+Springboot项目部署Jar和image两种方式

Springboot环境准备 利用spring官网快速创建springboot项目。 添加一个controller package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class…

新华三眼中的AI天路

ChatGPT的火爆&#xff0c;在全球范围内掀起了新一轮的AI风暴。如今&#xff0c;各行各业都在讨论AI&#xff0c;各个国家都在密集进行新一轮的AI基础设施建设与技术投入。 但眼前的盛景并非突然到来&#xff0c;就拿这一轮大模型热潮来说&#xff0c;谷歌早在2018年底就发布了…

协议速攻 IIC协议详解

介绍 IIC是一种 同步 半双工 串行 总线 同步 指的是同一根时钟线(SCL) 半双工 可以进行双向通信&#xff0c;但是收发不能同时进行&#xff0c;发的时候禁止接收&#xff0c;接的时候禁止发送 串行 数据是一位一位发送的 总线 两根线(SCL SDA)可以接多个IIC类型器件&#…

《统计学习方法》——逻辑斯蒂回归和最大熵模型

参考资料&#xff1a; 《统计学习方法》李航通俗理解信息熵 - 知乎 (zhihu.com)拉格朗日函数为什么要先最大化&#xff1f; - 知乎 (zhihu.com) 1 逻辑斯蒂回归 1.1 逻辑斯蒂回归 输入 x ( x ( 1 ) , x ( 2 ) , ⋯ , x ( n ) , 1 ) T x(x^{(1)},x^{(2)},\cdots,x^{(n)},1…

【动态规划算法练习】day11

文章目录 一、1312. 让字符串成为回文串的最少插入次数1.题目简介2.解题思路3.代码4.运行结果 二、1143. 最长公共子序列1.题目简介2.解题思路3.代码4.运行结果 三、1035. 不相交的线1.题目简介2.解题思路3.代码4.运行结果 总结 一、1312. 让字符串成为回文串的最少插入次数 1…

DevOps系列文章之 设计一个简单的DevOps系统

前置条件 gitlab gitlab-runner k8s docker 1. gitlab创建群组 创建群组的好处是,对项目进行分组,群组内的资源可以共享,这里创建了一个tibos的群组 2. 在群组创建一个项目 这里创建一个空白项目,项目名为Gourd.Test,将项目克隆到本地,然后在该目录下创建一个.net core3.1的w…

Spring Cloud Alibaba Seata源码分析

目录 一、Seata源码分析 1、Seata源码入口 1.1、2.0.0.RELEASE 1.2、2.2.6.RELEASE 2、Seata源码分析-2PC核心源码 3、Seata源码分析-数据源代理 3.1、数据源代理DataSourceProxy 4、Seata源码分析- Seata服务端&#xff08;TC&#xff09;源码 一、Seata源码分析 Sea…

P1dB、IIP3、OIP3、IMD定义及关系

P1dB 1分贝压缩输出功率。放大器有一个线性动态范围&#xff0c;在这个范围内&#xff0c;放大器的输出功率随输入功率线性增加。随着输入功率的继续增加&#xff0c;放大器进入非线性区&#xff0c;其输出功率不再随输入功率的增加而线性增加&#xff0c;也就是说&#xff0c;…

【新星计划·2023】Linux文件权限讲解

作者&#xff1a;Insist-- 个人主页&#xff1a;insist--个人主页 作者会持续更新网络知识和python基础知识&#xff0c;期待你的关注 前言 这篇文章&#xff0c;将带你详细的了解一下 Linux 系统里面有哪些重要的文件&#xff1f;。 不过&#xff0c;每个文件都有相当多的属性…

ROS学习篇之传感器(二)IMU(超核IMU HI266)

文章目录 一.确定IMU型号二.安装驱动1.找到驱动的包2.解压该压缩包3.安装步骤说明4.具体安装5.检查IMU的usb接口是否插到电脑 三.在RVIZ中的显示1.复制示例下的src里的文件复制到自己的src下2.自己的文件目录3.尝试编译一下4.示例的文件说明5.运行Demo6.配置Rviz 四.查看IMU的实…