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

文章目录

  • 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.

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

NSS [NSSCTF 2022 Spring Recruit]ezgame

NSS [NSSCTF 2022 Spring Recruit]ezgame 前端小游戏,乐。

Spring源码整体脉络介绍及源码编译

需完成的任务 类------------------------------------------BeanFactory----------------------------------------->Bean【BeanFactory调用getBean()生产出来的】 BeanFactory Spring顶层核心接口,使用了简单工厂模式【根据名字,生产出不同的Bean…

C#:AES的加密解密,用于明文加密

大白话理解&#xff1a;将明眼能看到的字符给用另一种读不懂的语言给翻译&#xff0c;就像是摩斯密码……就像base64加密&#xff0c;都有异曲同工之妙。 建一个新的类&#xff08;这里放了aes加密解密的方法&#xff09; public static class AesPassword{/// <summary&g…

大屏项目也不难

项目环境搭建 使用create-vue初始化项目 npm init vuelatest准备utils模块 业务背景&#xff1a;大屏项目属于后台项目的一个子项目&#xff0c;用户的token是共享的 后台项目 - token - cookie 大屏项目要以同样的方式把token获取到&#xff0c;然后拼接到axios的请求头中…

rain-nowcasting-using-deep-learning github:使用深度学习进行临近降水预报

来源 github地址 是什么 本资料库旨在阐述 "在应用于降雨预报的深度学习模型中合并雷达雨量图像和风速预测 "&#xff08; “Merging radar rain images and wind predictions in a deep learning model applied to rain nowcasting”&#xff09;一文中提出的深度…

群晖NAS搭建WebDV服务手机ES文件浏览器远程访问

文章目录 1. 安装启用WebDAV2. 安装cpolar3. 配置公网访问地址4. 公网测试连接5. 固定连接公网地址 转载自cpolar极点云文章&#xff1a;群晖NAS搭建WebDAV服务手机ES文件浏览器远程访问 有时候我们想通过移动设备访问群晖NAS 中的文件,以满足特殊需求,我们在群辉中开启WebDav服…

蓝桥杯专题-试题版含答案-【字母统计】【计算球体积】【16进制的简单运算】【C小加随机数】

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例点击跳转>软考全系列点击跳转>蓝桥系列 &#x1f449;关于作者 专注于Android/Unity和各种游…

JUC--CompletableFuture下

对计算速度进行选用 import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit;public class Test4 {public static void main(String[] args) {CompletableFuture<String> a CompletableFuture.supplyAsync(() -> {try { TimeUnit.SE…

详解JAVA Socket

目录 1.概述 2.使用 3.使用场景 3.1.web server中的网络通信 3.2.长连接 3.3.性能问题 1.概述 什么是网络通信&#xff1a; 就像打电话一样&#xff0c;两点间要通信&#xff0c;两点间就必须有连接&#xff0c;为了实现任意两个节点之间的通信&#xff0c;我们就必须采…

第三十九章Java成员方法的声明和调用

声明成员方法可以定义类的行为&#xff0c;行为表示一个对象能够做的事情或者能够从一个对象取得的信息。类的各种功能操作都是用方法来实现的&#xff0c;属性只不过提供了相应的数据。一个完整的方法通常包括方法名称、方法主体、方法参数和方法返回值类型&#xff0c;其结构…

C# PaddleInference 文字检测(只检测不识别)

效果 项目 Demo下载 代码 using OpenCvSharp.Extensions; using OpenCvSharp; using Sdcb.PaddleInference.Native; using Sdcb.PaddleInference; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using Sys…

phar协议文件包含

实验目的 通过本实验&#xff0c;了解php封装伪协议&#xff0c;掌握phar协议文件包含的用法 实验环境 操作机&#xff1a;kali 靶机&#xff1a;Windows 2007 实验地址&#xff1a;http://靶机ip/exp/include2/phar/phar1/ 用户名&#xff1a;college 密码&#xff1a;360C…

Vue :在 VSCode 中安装 yarn 并用 yarn 工具来控制 Vue 项目的详细过程

Ⅰ、 Yarn 工具简介&#xff1a; 1、什么是 yarn 工具: Yarn 是 facebook 发布的一款取代 npm 的资源包管理工具&#xff0c;是一个快速、可靠、安全的依赖管理工具&#xff0c;一款新的 JavaScript 资源包管理工具(吐槽下&#xff1a;最大的弊端是&#xff0c;要通过 npm 来…

在blender中使用python程序化建模

blender中&#xff0c;所有可以在Blender软件中的手动操作&#xff0c;基本都可以通过Python API 完成 那么就可以用这个完成程序化生成 下面我给出一个简单的方块建模程序&#xff1a; 在scripting中&#xff0c;可以添加file&#xff0c;然后向场景中心放置一个正方体 首…

RK3588平台开发系列讲解(Camera篇)OV569摄像头调试

文章目录 一、摄像头识别检测二、查看摄像头支持的格式三、摄像头采集格式查询四、摄像头采集格式查询沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇章主要讲解OV569摄像头调试。 OV5695 是一种图像传感器,用于摄像头设备。要进行 OV5695 摄像头的调试,通常涉…

100种思维模型之能力圈思维模型-91

芒格说&#xff1a; “ 一个人在一生中可以真正得到的真见卓识仍然非常有限&#xff0c;所以正确的决策必须局限在自己的 ‘ 能力圈’ 以内。 ” 巴菲特说&#xff1a; “对你的 能力圈 来说&#xff0c;最重要的不是能力圈的范围大小&#xff0c;而是你如何能够 确定能…

Django核心

安装django pip install django # pip install django3.1.6创建django项目 在一个项目中可以包含多个应用程序。 django-admin startapp app_name #创建一个应用程序 django-admin startproject project_name #创建一个项目运行django项目 python manage.py runserver 80…

2. PS基本操作

因为网页美工大部分效果图都是利用PS ( Photoshop )来做的,所以以后我们大部分切图工作都是在PS里面完成 ●文件—>打开&#xff1a;可以打开我们要测量的图片 ●CtrlR : 可以打开标尺&#xff0c;或者视图—>标尺 ●右击标尺&#xff0c;把里面的单位改为像素 ●Ctrl加号…

Spring Boot实战:拦截器和监听器的应用指南

当使用Spring Boot时&#xff0c;我们可以通过拦截器&#xff08;Interceptor&#xff09;和监听器&#xff08;Listener&#xff09;来实现对请求和响应的处理。拦截器和监听器提供了一种可插拔的机制&#xff0c;用于在请求处理过程中进行自定义操作&#xff0c;例如记录日志…

【保姆级教程】PyCharm通过SSH远程连接ModelArts

文章目录 一、创建Notebook二、配置SSH三、配置远程Python解释器四、成果展示 一、创建Notebook 首先&#xff0c;找到云资源下面的 ModelArts&#xff0c;然后点击并进入 ModelArts控制台。 在ModelArts控制台中&#xff0c;点击开发环境下的 Notebook 。然后点击创建&#x…