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

news/2024/7/23 15:32:49 标签: 前端, python, dreamweaver, 学习, 笔记

文章目录

  • 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.niftyadmin.cn/n/1006417.html

相关文章

centos7.X安装docker---个人学习经验

工具:VMware Workstation Pro 16.1 系统:CentOS-7-x86_64-DVD-2009 docker:docker-ce-24.0.2-1 说明:这是个人在学习安装docker的时候一些经验,如有不对的还请指教,有些步骤因个人专业能力和时间问题并未…

【Django入门系列】Django基础

在本章中,我们将学习Django的基础知识,包括创建第一个Django项目、Django项目的组织结构、模型-视图-控制器(MVC)设计模式、Django中的URL和路由以及Django的模板语言。 一、创建第一个Django项目 首先,我们需要安装…

c++11 标准模板(STL)(std::basic_ostream)(二)

定义于头文件 <ostream> template< class CharT, class Traits std::char_traits<CharT> > class basic_ostream : virtual public std::basic_ios<CharT, Traits> 类模板 basic_ostream 提供字符流上的高层输出操作。受支持操作包含有格式…

基于Java校园车辆管理系统设计实现(源码+lw+部署文档+讲解等)

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

力扣、每日一练:爬楼梯

文章目录 一、题目二、解题思路&#xff1a;三、考察的知识点&#xff1a;四、使用Python语言巧妙实现&#xff1a;五、总结一下收获&#xff1a; 一、题目 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢&am…

2023-07-01 用C语言把科学计数法转换为普通数字,使用double value; sscanf(str, “%lf“, value );就可以做到。

一、在科学计数法中&#xff0c;为了使公式简便&#xff0c;可以用带 “E” 的格式表示。例如 1.09乘10的7次方&#xff0c;可简写为 “1.09E07” 的形式&#xff0c;其中 ”E“ 是 exponent(指数) 的缩写&#xff0c;可以不区分e的大小写&#xff0c;用e或者E都可以。 二、比…

抖音SEO矩阵源码开发(一)

前言&#xff1a; 1.抖音SEO矩阵系统源码开发 是一项技术密集型工作&#xff0c;需要对大数据处理、人工智能等领域有深入了解。该系统开发过程中需要用到多种编程语言在服务器上安装LNMP环境&#xff0c;包括Linux操作系统、Nginx、MySQL、PHP等&#xff0c;如Java、Python等…

Unity - 搬砖日志 - UGUI合批优化 - Overlap(UI AABB 有重叠), Z != 0 照样合批的方案

文章目录 环境目的Screen Space - Overlay优化限制该方案起源 环境 Unity : 2020.3.37f1 Pipeline : BRP &#xff08;另一个项目在 2021.1.xx 的 LTS 下的 URP 管线同样如此&#xff0c;目测&#xff1a;因为 UGUI 不受渲染管线切换而变化&#xff09; 目的 便于索引&#…