Quiz 14_2-1: Using Web Services | Python for Everybody 配套练习_解题记录

news2024/11/16 9:29:34

文章目录

  • Python for Everybody
  • 课程简介
  • Quiz 14_2-1: Using Web Services
    • 单选题(1-15)
    • 操作题
      • Autograder : Extracting Data from XML


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 14_2-1: Using Web Services

Web services allow a program to access data available in a different server.


单选题(1-15)

  1. What is “serialization” when we are talking about web services?
  • Marking each network packet so it can be put back into order on the receiving system
  • Making it so that dictionaries can maintain their keys in sorted order
  • Sorting all the data stored in a tuple
  • The act of taking data stored in a program and formatting it so it can be sent across the network
  1. What is the name of the Python library to parse XML data?
  • xml-misc
  • xml.etree.ElementTree
  • xml2
  • xml.json
  1. Which of the following are not commonly used serialization formats?
  • XML
  • TCP
  • HTTP
  • Dictionaries
  • JSON
  1. What is the method to cause Python to parse XML that is stored in a string?
  • readall()
  • fromstring()
  • parse()
  • xpath()
  • extract()
  1. In this XML, which are the “complex elements”?
<people>
    <person>
       <name>Chuck</name>
       <phone>303 4456</phone>
    </person>
    <person>
       <name>Noah</name>
       <phone>622 7421</phone>
    </person>
</people>
  • phone
  • person
  • name
  • Noah
  • people
  1. In this XML, which are the “simple elements”?
<people>
    <person>
       <name>Chuck</name>
       <phone>303 4456</phone>
    </person>
    <<person>
           <name>Noah</name>
       <phone>622 7421</phone>
    </person>
</people>
  • phone
  • name
  • people
  • person
  • Noah
  1. In the following XML, which are attributes?
<person>
  <name>Chuck</name>
  <phone type="intl">
     +1 734 303 4456
  </phone>
  <email hide="yes" />
</person>
  • type
  • email
  • person
  • name
  • hide
  1. In the following XML, which node is the parent node of node e
<a>
  <b>X</b>
  <c>
    <d>Y</d>
    <e>Z</e>
  </c>
</a>
  • c
  • e
  • a
  • b
  1. Looking at the following XML, what text value would we find at path “/a/c/e”
<a>
  <b>X</b>
  <c>
    <d>Y</d>
    <e>Z</e>
  </c>
</a>
  • a
  • Y
  • Z
  • e
  • b
  1. What is the purpose of XML Schema?
  • To transfer XML data reliably during network outages
  • To establish a contract as to what is valid XML
  • A Python program to tranform XML files
  • To compute SHA1 checksums on data to make sure it is not modified in transit
  1. If you were building an XML Schema and wanted to limit the values allowed in an xs:string field to only those in a particular list, what XML tag would you use in your XML Schema definition?
  • xs:sequence
  • xs:enumeration
  • xs:complexType
  • xs:element
  • maxOccurs
  1. For this XML Schema:
<xs:complexType name=”person”>
  <xs:sequence>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="age" type="xs:integer"/>
    <xs:element name="dateborn" type="xs:date"/>
  </xs:sequence>
</xs:complexType>

And this XML,

<person>
   <lastname>Severance</lastname>
   <Age>17</Age>
   <dateborn>2001-04-17</dateborn>
</person>

Which tag is incorrect?

  • lastname
  • person
  • age
  • Age
  • dateborn
  1. What does the “Z” mean in this representation of a time:
2002-05-30T09:30:10Z
  • The local timezone for this time is New Zealand
  • This time is in the UTC timezone
  • The hours value is in the range 0-12
  • This time is Daylight Savings Time
  1. What is a good time zone to use when computers are exchanging data over APIs?
  • Universal Time / GMT
  • The local time zone of the sending computer
  • The local time zone of the receiving computer
  • The local time zone of the sending computer without daylight savings time
  1. Which of the following dates is in ISO8601 format?
  • 05/30/2002
  • 2002-05-30T09:30:10Z
  • May 30, 2002
  • 2002-May-30

操作题

Autograder : Extracting Data from XML

Extracting Data from XML

In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/geoxml.py. The program will prompt for a URL, read the XML data from that URL using urllib and then parse and extract the comment counts from the XML data, compute the sum of the numbers in the file.

We provide two files for this assignment. One is a sample file where we give you the sum for your testing and the other is the actual data you need to process for the assignment.

  • Sample data: http://py4e-data.dr-chuck.net/comments_42.xml
    (Sum=2553)
  • Actual data: http://py4e-data.dr-chuck.net/comments_1577745.xml
    (Sum ends with 90)

You do not need to save these files to your folder since your program will read the data directly from the URL. Note: Each student will have a distinct data url for the assignment - so only use your own data url for analysis.
Data Format and Approach
The data consists of a number of names and comment counts in XML as follows:

<comment>
  <name>Matthias</name>
  <count>97</count>
</comment>

You are to look through all the <comment> tags and find the <count> values sum the numbers. The closest sample code that shows how to parse XML is geoxml.py. But since the nesting of the elements in our data is different than the data we are parsing in that sample code you will have to make real changes to the code.
To make the code a little simpler, you can use an XPath selector string to look through the entire tree of XML for any tag named ‘count’ with the following line of code:

counts = tree.findall('.//count')

Take a look at the Python ElementTree documentation and look for the supported XPath syntax for details. You could also work from the top of the XML down to the comments node and then loop through the child nodes of the comments node.

Sample Execution

$ python3 solution.py
Enter location: http://py4e-data.dr-chuck.net/comments_42.xml
Retrieving http://py4e-data.dr-chuck.net/comments_42.xml
Retrieved 4189 characters
Count: 50
Sum: 2...

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

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

相关文章

Echarts折线图默认不显示数据圆点,鼠标hover时折线图上才显示圆点

option {......tooltip: {trigger: axis,},series: [{symbol: circle,symbolSize: 5,showSymbol: false, // 只有在 tooltip hover 的时候显示symbolitemStyle: { // symbol样式normal: {color: rgb(255, 255, 255),borderColor: rgba(255, 255, 255, 0.2), // symbol边框颜色…

6.20、JAVA 初识序列化与反序列化

初识序列化与反序列化 1 概述 序列化是指将对象的状态信息转换为可以存储或传输形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后可以通过从存储区中读取或者反序列化对象的状态,重新创建该对象. 序列化:利用ObjectOutputStream,把对象的信息,按照固定…

【QT】如何自定义QMessageBox的窗口大小,通过继承QDialog重新实现美观的弹窗

目录 1. QMessageBox原有的弹窗2. 网上第一种方法&#xff1a;通过样式表setStyleSheet实现改变弹窗大小&#xff08;总体不美观&#xff09;3. 网上第二种方法&#xff1a;重写ShowEvent()改变弹窗大小&#xff08;总体也不美观&#xff09;4. 最好的办法&#xff1a;继承QDia…

centos安装k8s

1. 前置 俩台centos服务器,不过多说明,教程基于centos 2. hosts配置 我这样配置&#xff0c;最后没发现那块有联动&#xff0c;望大佬更正 vim /etc/hosts 在末尾添加 192.***** master 192.*** note3. 防火墙 说是要关闭防火墙&#xff0c;我俩台服务器都是基于内网&…

服务器数据库中遭受Devos勒索病毒攻击后解密处理方法,勒索病毒数据恢复

在当今数字化时代&#xff0c;服务器数据库的安全性备受关注。然而&#xff0c;网络安全威胁依然存在&#xff0c;勒索病毒如Devos仍然是一种常见的攻击计算机病毒。最近&#xff0c;收到很多企业的求助&#xff0c;企业的财务系统账套遭到了Devos勒索病毒攻击&#xff0c;导致…

js数组中对象的替换,替换原数组 lodash中一些常用的方法(很实用)

代码 let myArray [{name: John, age: 25},{name: Alice, age: 30},{name: Bob, age: 35} ];// 要替换的对象 let objToReplace {name: Alice, age: 30};// 替换为的对象 let replacementObj {name: Alex, age: 28};// 使用forEach方法 myArray.forEach((obj, index) > …

浙大滨江院Om中心发布首个大规模图文配对遥感数据集,让通用基础模型也能服务遥感领域...

写在前面 2021 年年底&#xff0c;OpenAI 发布了 CLIP&#xff0c;利用带噪的图像-文本配对数据预训练的视觉语言模型&#xff0c;展示了前所未有的图像-文本关联能力&#xff0c;在各种下游任务中取得了惊人的结果。虽然取得了很大的进展&#xff0c;但是这类通用视觉语言基础…

Visual C++中的虚函数和纯虚函数(以策略设计模式为例)

我是荔园微风&#xff0c;作为一名在IT界整整25年的老兵&#xff0c;今天来说说Visual C中的虚函数和纯虚函数。该系列帖子全部使用我本人自创的对比学习法。也就是当C学不下去的时候&#xff0c;就用JAVA实现同样的代码&#xff0c;然后再用对比的方法把C学会。 直接说虚函数…

微信小程序 rich-text富文本框 怎么设置里面节点的样式

1、在JS中我们获取数据&#xff0c;在没有类名的情况下 使用正则匹配你想要添加演示的节点 res[1].data[0].f_content为rich-text里面的节点 如图 代码&#xff1a;让获取的节点中的图片的最大宽度为100%,高度为auto this.content res[1].data[0].f_content.replace(/\<…

数据库连接与操作怎么学习? - 易智编译EaseEditing

学习数据库连接和操作是进行数据管理和处理的关键技能之一。下面是一些建议&#xff0c;可以帮助您学习数据库连接和操作&#xff1a; 学习数据库基础知识&#xff1a; 首先&#xff0c;了解数据库的基本概念、术语和原理。掌握关系型数据库和非关系型数据库的特点以及它们之…

Spring Boot中的Elasticsearch自动配置

Spring Boot中的Elasticsearch自动配置 Elasticsearch是一个基于Lucene的分布式全文搜索引擎&#xff0c;它在搜索、分析等方面具有出色的表现。Spring Boot中的Elasticsearch自动配置为我们提供了一种快速集成Elasticsearch的方式&#xff0c;使我们可以在Spring Boot应用程序…

【Unity每日一记】常见的类你都掌握了吗,没有就过来看看吧

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;uni…

layui弹出层laydate时间选择一闪而过,无法弹出时间选择

问题&#xff1a;layUI日期框弹不出&#xff0c;一闪而过 laydate.render({elem: #ctime,type: datetime,trigger:click }); 解决方案&#xff1a;关键代码&#xff0c;添加如下代码 trigger:click 实现效果

浏览器基础原理-安全: HTTPS

HTTP协议的历史: HTTP协议的目的很单纯, 就是为了传输超文本文件, 所以早期的 HTTP 一直保持着明文传输数据的特征, 但是中间很有可能会被截取或者篡改, 即收到中间人攻击. 解析HTTP协议栈层面: HTTPS往里面加入了安全层, 它的指责是: 对发起HTTP请求的数据进行加密和对接收…

Redis实战篇(二)

三、优惠卷秒杀 3.1 全局唯一ID 每个店铺都可以发布优惠券&#xff1a; 当用户抢购时&#xff0c;就会生成订单并保存到tb_voucher_order这张表中&#xff0c;而订单表如果使用数据库自增ID就存在一些问题&#xff1a; id的规律性太明显 受单表数据量的限制 场景分析一&am…

初学mybatis(二)CRUD操作及配置解析

学习回顾&#xff1a;初学mybatis&#xff08;一&#xff09; 一、namespace 1、将上面案例中的UserMapper接口改名为 UserDao&#xff1b;2、将UserMapper.xml中的namespace改为为UserDao的路径 .3、再次测试 结论&#xff1a; 配置文件中namespace中的名称为对应Mapper接口或…

Python基本操作

前言 啦啦啦&#xff0c;现在开始,打算做一期Python基础教程&#xff0c;欢迎大家来看哦&#xff01; 导读 这期文章真的是Python基础中的基础&#xff0c;相信有一定编程基础的小伙伴们都一定能看懂的… 本文共分为以下几个部分&#xff1a; 数与运算符基本输入输出注释模…

Linux环境安装openJDK

现在越来越多的开发者使用 openJDK &#xff0c;当然这也是一种趋势 官网下载&#xff1a; https://jdk.java.net/java-se-ri/8-MR5这里以 jdk8 为例 配置环境变量 看网上的教程&#xff0c;好多人都推荐去这个官网下载&#xff1a; https://hg.openjdk.org/其实这个是 O…

算法笔记——数组篇

整理一下刷过的题型&#xff0c;持续更新&#xff0c;参照代码随想录 代码随想录数组篇 二分法 力扣相关题目&#xff1a; 704. 二分查找 只适用于排序有序数组&#xff0c;且没有重复元素。主要是有两种写法&#xff0c;二分查找涉及的很多的边界条件&#xff0c;逻辑比较简单…

V-Box智能车载终端-OBUYZN2

1 产品概览 OBUYZN2型智能车载终端&#xff08;以下简称&#xff09;是 型智能车载终端&#xff08;以下简称&#xff09;是 型智能车载终端&#xff08;以下简称&#xff09;是 型智能车载终端&#xff08;以下简称&#xff09;是 组成智能网联 系统 的核心数据交互设备 &…