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

news2024/11/17 20:35:43

文章目录

  • Python for Everybody
    • 课程简介
    • Quiz 14_2-2: Using Web Services
    • 单选题(1-15)
    • 操作题
      • Autograder 1: Extract Data from JSON
      • Autograder 2: Calling a JSON API


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-2: Using Web Services

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


单选题(1-15)

  1. Who is credited with getting the JSON movement started?
  • Mitchell Baker
  • Douglas Crockford
  • Bjarne Stroustrup
  • Pooja Sankar
  1. Who is credited with the REST approach to web services?
  • Roy Fielding
  • Daphne Koller
  • Vint Cerf
  • Bjarne Stroustrup
  • Leonard Klienrock
  1. What Python library do you have to import to parse and handle JSON?
  • import json
  • import re
  • ElementTree
  • BeautifulSoup
  1. Which of the following is true about an API?
  • An API defines the header bits in the first 8 bits of all IP packets
  • An API is a contract that defines how to use a software library
  • An API keeps servers running even when the power is off
  • An API defines the pin-outs for the USB connectors
  1. What is the method used to parse a string containing JSON data so that you can work with the data in Python?
  • json.connect()
  • json.parse()
  • json.loads()
  • json.read()
  1. Which of the following is a web services approach used by the Twitter API?
  • CORBA
  • REST
  • SOAP
  • XML-RPC
  1. What kind of variable will you get in Python when the following JSON is parsed:
[ "Glenn", "Sally", "Jen" ]
  • A dictionary with three key / value pairs
  • Three tuples
  • A dictionary with one key / value pair
  • One Tuple
  • A list with three items
  1. What kind of variable will you get in Python when the following JSON is parsed:
{ "id" : "001",
  "x" : "2",
  "name" : "Chuck"
}
  • A dictionary with three key / value pairs
  • A tuple with three items
  • A list with three items
  • A list with six items
  • A list of tuples
  1. Which of the following is not true about the service-oriented approach?
  • An application runs together all in one place
  • An application makes use of the services provided by other applications
  • Standards are developed where many pairs of applications must work together
  • Web services and APIs are used to transfer data between applications
  1. If the following JSON were parsed and put into the variable x,
{
    "users": [
        {
            "status": {
                "text": "@jazzychad I just bought one .__.",
             },
             "location": "San Francisco, California",
             "screen_name": "leahculver",
             "name": "Leah Culver",
         },
   ...

what Python code would extract “Leah Culver” from the JSON?

  • x[0][“name”]
  • x[“users”][0][“name”]
  • x[“users”][“name”]
  • x[“name”]
  1. Which of these two web service approaches is preferred in most modern service-oriented applications?
  • REST - Representational state transfer
  • SOAP - Simple Object Access Protocol
  1. What library call do you make to append properly encoded parameters to the end of a URL like the following:
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=Ann+Arbor%2C+MI
  • re.encode()
  • re.match()
  • urllib.parse.urlencode()
  • urllib.urlcat()
  1. What happens when you exceed the Google geocoding API rate limit?
  • The API starts to perform very slowly
  • You cannot use the API for 24 hours
  • You canot use the API until you respond to an email that contains a survey question
  • Your application starts to perform very slowly
  1. What protocol does Twitter use to protect its API?
  • SHA1-MD5
  • SOAP
  • Java Web Tokens
  • PKI-HMAC
  • WS*Security
  • OAuth
  1. What header does Twitter use to tell you how many more API requests you can make before you will be rate limited?
  • x-request-count-down
  • content-type
  • x-max-requests
  • x-rate-limit-remaining

操作题

Autograder 1: Extract Data from JSON

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

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.json
    (Sum=2553)
  • Actual data: http://py4e-data.dr-chuck.net/comments_1577746.json
    (Sum ends with 73)

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
The data consists of a number of names and comment counts in JSON as follows:

{
  comments: [
    {
      name: "Matthias"
      count: 97
    },
    {
      name: "Geomer"
      count: 97
    }
    ...
  ]
}

The closest sample code that shows how to parse JSON and extract a list is json2.py. You might also want to look at geoxml.py to see how to prompt for a URL and retrieve data from a URL.

Sample Execution

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

Autograder 2: Calling a JSON API

In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/geojson.py. The program will prompt for a location, contact a web service and retrieve JSON for the web service and parse that data, and retrieve the first place_id from the JSON. A place ID is a textual identifier that uniquely identifies a place as within Google Maps.

API End Points

To complete this assignment, you should use this API endpoint that has a static subset of the Google Data:

http://py4e-data.dr-chuck.net/json?

This API uses the same parameter (address) as the Google API. This API also has no rate limit so you can test as often as you like. If you visit the URL with no parameters, you get “No address…” response.

To call the API, you need to include a key= parameter and provide the address that you are requesting as the address= parameter that is properly URL encoded using the urllib.parse.urlencode() function as shown in http://www.py4e.com/code3/geojson.py

Make sure to check that your code is using the API endpoint as shown above. You will get different results from the geojson and json endpoints so make sure you are using the same end point as this autograder is using.

Test Data / Sample Execution

You can test to see if your program is working with a location of “South Federal University” which will have a place_id of “ChIJNeHD4p-540AR2Q0_ZjwmKJ8”.

$ python3 solution.py
Enter location: South Federal University
Retrieving http://...
Retrieved 2453 characters
Place id ChIJNeHD4p-540AR2Q0_ZjwmKJ8

Turn In

Please run your program to find the place_id for this location:

University of Greifswald

Make sure to retreive the data from the URL specified above and not the normal Google API. Your program should work with the Google API - but the place_id may not match for this assignment.

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

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

相关文章

12 | 领域建模:如何用事件风暴构建领域模型?

还记得微服务设计为什么要选择 DDD 吗? 其中有一个非常重要的原因,就是采用 DDD 方法建立的领域模型,可以清晰地划分微服务的逻辑边界和物理边界。可以说,在 DDD 的实践中,好的领域模型直接关乎微服务的设计水平。因此…

代码随想录算法训练营第4天| 24. 两两交换链表中的节点 19.删除链表的倒数第N个节点 面试题 02.07. 链表相交 142.环形链表II

今日学习的文章链接,或者视频链接 第二章 链表part02 自己看到题目的第一想法 看完代码随想录之后的想法 24: 注意链表的操作: class Solution { public:ListNode* swapPairs(ListNode* head) {auto dummyhead new ListNode(0,head);auto prev …

Apache Doris (五) :Doris分布式部署(二) FE扩缩容

目录 1. 通过MySQL客户端连接Doris ​​​​​​​​​​​​​​2. FE Follower扩缩容 ​​​​​​​3. FE Observer 扩缩容 ​​​​​​​​​​​​​​4. FE扩缩容注意点 进入正文之前,欢迎订阅专题、对博文点赞、评论、收藏,关注IT贫道&#…

超详细|粒子群优化算法及其MATLAB实现

本文主要介绍粒子群算法的背景与理论,并结合对应部分的MATLAB程序对其实现流程做了阐述,代码获取方式见文末。 00 文章目录 1 粒子群优化算法 2 问题导入 3 MATLAB程序实现 4 改进策略 5 展望 01 粒子群优化算法 1.1 粒子群优化算法背景 近年来&…

亿发软件:智慧中药房信息化建设,中医药安全煎煮解决方案

传统的中药饮片煎煮服用较为繁琐,局限了诸多人群的使用。为了优化医疗服务,并满足患者不断增长的中医药需求,智慧中药房的概念应运而生。智慧化中药房通过信息化和自动化相结合,旨在提高中药处方的管理和效率。下面就让我们了解一下中药配方颗…

创建一个nuxt项目

yarn create nuxt-app ssr 启动项目 如果使用npm run start 可能会报错,提示需要配置为开发环境 可以先执行npm run dev 看看

HPM6750系列--第三篇 搭建MACOS编译和调试环境

一、目的 在上一篇《HPM6750系列--第二篇 搭建Ubuntu开发环境》我们介绍了Ubuntu上开发HPM6750,本篇主要介绍MAC系统上的开发环境的搭建过程,整个过程和Ubuntu上基本类似。 二、准备 首先我们在Mac电脑上打开一个terminal,然后创建一个…

苹果Vision Pro手势+眼球融合交互的奥秘

毫无疑问,Vision Pro在眼球追踪手势的融合交互体验上,给AR/VR头戴设备带来了新突破,在用户体验上的提升非常明显。 ​那么,为什么Vision Pro上这一功能会被如此值得关注呢?为了弄清楚,我们先来看看主流VR设…

037:mapboxGL输入经纬度,地址坐标转换,弹出位置点地址信息

第037个 点击查看专栏目录 本示例的目的是介绍演示如何在vue+mapbox中输入经纬度,地址坐标转换,弹出位置点地址信息. 直接复制下面的 vue+mapbox源代码,操作2分钟即可运行实现效果 文章目录 示例效果配置方式示例源代码(共158行)相关API参考:专栏目标示例效果 配置方式…

配置Jenkins slave agent(通过jnlp)方式连接

上一章,使用ssh的方式添加了两个agent,并都成功完成了构建任务,这一章使用jnlp的方式配置agent,jnlp方式配置agent有个好处,就是agent是主动去找到Master请求连接的,master->agent的通道可以配置一个age…

【AUTOSAR】BMS开发实际项目讲解(二十九)----电池管理系统电池充放电功率控制与SOC

电池充放电功率控制 关联的系统需求 Sys_Req_3901、Sys_Req_3902、Sys_Req_3903、Sys_Req_3904; 功能实现描述 电池充放电功率控制主要包括以下内容: 60S可用功率 参见[CELL] 30S可用功率 参见[CELL] 10S可用功率 参见[CELL] SOP算法 ID Description ASI…

LVDS接口ADC要点数据采集流程

一:要点 1.如果两片AD,四路输出做了同步化处理之后,一定只用同步化模块读时钟(一片AD的时钟)去上传数据,到DDR3模块。 2.ADS42和LTC2208的ADC的数据伴随时钟都来源与输入的采样时钟(有些采样时…

虚拟机上用docker + nginx跑前端并支持https和http

情况是这样,我在虚拟机上,使用docker跑前端,需要这个前端支持https,原http的话自动跳转到https。另外,前端部署使用了负载均衡,即使用了3个docker跑前端:1个入口,另外2个是前端&…

Wi-Fi模块(ESP8266)详解

Wi-Fi模块——ESP8266 0. Wi-Fi模块概述1. 常见的Wi-Fi模块2. ESP8266模块2.1 概念2.2 特点 3. STM32F103C8T6使用ESP8266进行无线通信的示例代码 0. Wi-Fi模块概述 Wi-Fi模块是一种用于无线通信的设备,它能够通过Wi-Fi技术实现设备之间的无线数据传输和互联网连接…

java面试Day18

1.什么是 MySQL 执行计划?如何获取执行计划并对其进行分析? MySQL 执行计划是指 MySQL 查询优化器生成的一份详细的查询执行计划,它展示了 MySQL 在执行查询时所采取的具体执行计划,包括表的访问顺序、数据读取方式、使用的索引、…

大模型入局传统算法,LLMZip基于LLaMA-7B实现1MB文本压缩率90%!

论文链接: https://arxiv.org/abs/2306.04050 随着以ChatGPT、GPT-4为代表的AI大模型逐渐爆火进入公众视野,各行各业都开始思考如何更好的使用和发展自己的大模型,有一些评论甚至认为大模型是以人工智能为标志的第四次产业革命的核心竞争产品…

11.窗口看门狗-WWGD

1.窗口看门狗概述: (1)之所以称为窗口是因为其喂狗时间是一个有上下限的范围内(窗口),可以通过设定相关寄存器,设定其上限时间(下限时间固定)。喂狗的时间不能过早也不能过晚。而独立看门狗限制喂狗时间在0-x内&#…

Zigbee模块(CC2530)详解

Zigbee模块(CC2530) 0. Zigbee概述1. 常见的Zigbee模块2. CC2530模块3. STM32使用CC2530模块方法代码模板 0. Zigbee概述 Zigbee是一种无线通信协议,专为低功耗、低数据速率的应用而设计。它工作在2.4 GHz频段,常用于家庭自动化、…

MYSQL-SELECT语句超详解

目录 前言: SELECT语法 示例 单个字段查询 多个字段查询 查询所有字段 没有FROM的SELECT 查询系统时间 数值计算 虚拟表dual WHERE语句 示例 AND OR 比较运算符 AND OR 运算符优先级 IN NOT IN BETWEEN NOT BETWEEN LIKE EXISTS ORDER BY LIMIT …

SpringBoot(三)SpringBoot搭建简单服务端

之前的两篇文章介绍了如何使用ItelliJ社区版创建SpringBoot项目以及SpringBoot的starter。本篇,介绍下如何使用SpringBoot搭建一个简单的服务端,实现一个新用户注册的场景,供前端和移动端去使用。本篇需要你对SpringBoot的starter&#xff0c…