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

文章目录

  • 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.hqwc.cn/news/13683.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 命令之find

find 命令 1. 作用 命令用于在指定目录下以及其子母路查找文件和目录。 2. 语法 find [path] [expression] 不指定path的默认为当前路径 2.1 常见的参数 -name pattern&#xff1a;按文件名查找&#xff0c;支持使用通配符 * 和 ?。 -type type&#xff1a;按文件类型查…

【kubernetes系列】kubernetes之initcontainer初始化容器

概述 Init Container就是用来做初始化工作的容器&#xff0c;可以是一个或者多个&#xff0c;如果有多个的话&#xff0c;这些容器会按定义的顺序依次执行&#xff0c;只有所有的Init Container执行完后&#xff0c;主容器才会被启动。我们知道一个Pod里面的所有容器是共享数据…

<Java导出Excel> 4.0 Java实现Excel动态模板字段增删改查

思路&#xff1a; 主要是同时操作两张表&#xff1a;一张存储数据的表&#xff0c;一张存储模板字段的表&#xff1b; 查询&#xff1a;只查询模板字段的表&#xff1b; 新增&#xff0c;修改&#xff0c;删除&#xff1a;需要同时操作两张表中的字段 如果两张表字段不一致&…

【Mac】安装DbServer

1.下载 链接: https://pan.baidu.com/s/13Vzsv1sLAq-J8RsRgtL-pw 提取码: 8gsr 2.安装 如果提示已损坏&#xff0c;无法打开。 解决方式&#xff1a; 打开“终端”&#xff0c;输入命令&#xff1a;sudo spctl --master-disable&#xff0c;这个过程中会提示要输入密码&…

硬件电路设计--运算放大器(一)参数和分类

文章目录 前言一、运放分类1.1 功能分类1.2 按单颗IC封装1.3 第一脚的判断 二、运放参数2.1 理想运放2.2 实际运放2.3 数据手册中的重要参数2.3.1 供电电压Vs&#xff08;power supply&#xff09;2.3.2 虚短虚断2.3.3 输入偏置电流Ib2.3.4 噪声Vn2.3.5 静态电流IQ2.3.6 输入失…

【Distributed】分布式监控系统zabbix应用(一)

文章目录 前言一、Zabbix基本概述1. Zabbix 的概念2. Zabbix 的工作原理3. Zabbix 6.0 新特性3.1 Zabbix 可以实现高可用3.2 Zabbix 新增监控系统 4. Zabbix 的构成5. Zabbix 的功能组件5.1 数据库5.2 Web 界面5.3 Zabbix Agent5.4 Zabbix Proxy5.5 Java Gateway 6. Zabbix 和 …

Oracle19c默认用户名system密码不正确不能登录问题解决

Oracle19c默认用户名system密码不正确不能登录问题解决 1、oracle 命令乱码问题 oracle乱码问题一般是由于oracle字符集设置和操作系统字符集设置不一致造成的。 查看oracle字符集方式如下&#xff1a; 1.进入sqlplus 命令&#xff1a; sqlplus /nolog2.以系统管理员身份连…

20中文字符识别(matlab程序)

1.简述 随着计算机科学的飞速发展&#xff0c;以图像为主的多媒体信息迅速成为重要的信息传递媒介&#xff0c;在图像中&#xff0c;文字信息(如新闻标题等字幕) 包含了丰富的高层语义信息&#xff0c;提取出这些文字&#xff0c;对于图像高层语义的理解、索引和检索非常有帮助…

android studio 4.0以上隐藏调用方法参数名提示

引入&#xff1a; android studio在编辑代码的时候&#xff0c;调用函数时会接口处会自动提示参数名&#xff0c;方便代码书写时对传参命名的规范性。 可以如果代码是魂效过的&#xff0c;那会适得其反&#xff0c;l,l1,l2,i,i1,i2这样的参数名提醒反而会混淆视听。 这时候可…

Vue项目在nginx部署启动

目录 1.打包 2.移动文件夹 3.修改配置文件 4.重启nginx即可通过指定端口访问。 1.打包 在package.json有一段代码是命令执行的&#xff0c;代码所示打包命令为build:prod,所以打包命令为npm install build:prod. "scripts": {"dev": "vue-cli-servi…

在SpringBoot中对RabbitMQ三种使用方式

基于API的方式 1.使用AmqpAdmin定制消息发送组件 Autowiredprivate AmqpAdmin amqpAdmin;Testpublic void amqpAdmin(){//1.定义fanout类型的交换器amqpAdmin.declareExchange(new FanoutExchange("fanout_exchange"));//2.定义两个默认持久化队列,分别处理email和sm…

TLS/SSL 协议

TLS/SSL 协议的工作原理 TLS/SSL 协议的工作原理 • 身份验证 • 保密性 • 完整 TLS/SSL 发展 TLS 协议 • Record 记录协议 • 对称加密 • Handshake 握手协议 • 验证通讯双方的身份 • 交换加解密的安全套件 • 协商加密参 TLS 安全密码套件解 对称加密的工作原理&am…