Quiz 13: Network Programming | Python for Everybody 配套练习_解题记录

news2024/11/19 3:31:38

文章目录

  • Python for Everybody
  • 课程简介
    • Quiz 13: Network Programming
    • 单选题(1-11)
    • 操作题
      • Autograder 1: Request-Response Cycle
      • Autograder 2: Scraping HTML Data with BeautifulSoup
      • Autograder 3: Following Links with BeautifulSoup


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 13: Network Programming

We take a quick look at how data moves across the network using the HyperText Transport Protocol (HTTP) and how we write programs to read data across the network.

单选题(1-11)

  1. What do we call it when a browser uses the HTTP protocol to load a file or page from a server and display it in the browser?
  • SMTP
  • The Request/Response Cycle
  • DECNET
  • Internet Protocol (IP)
  • IMAP
  1. What separates the HTTP headers from the body of the HTTP document?
  • Four dashes
  • X-End-Header: true
  • A blank line
  • A less-than sign indicating the start of an HTML tag
  1. Which of the following is most similar to a TCP port number?
  • A telephone number
  • A street number in an address
  • A telephone extension
  • The distance between two locations
  • The GPS coordinates of a building
  1. What must you do in Python before opening a socket?
  • import tcp-socket
  • _socket = true
  • import socket
  • import tcp
  • open socket
  1. In a client-server application on the web using sockets, which must come up first?
  • it does not matter
  • client
  • server
  1. Which of the following TCP sockets is most commonly used for the web protocol (HTTP)?
  • 80
  • 22
  • 119
  • 25
  • 23
  1. Which of the following is most like an open socket in an application?
  • The ringer on a telephone
  • An “in-progress” phone conversation
  • Fiber optic cables
  • The chain on a bicycle
  • The wheels on an automobile
  1. What does the “H” of HTTP stand for?
  • Hyperspeed
  • wHolsitic
  • Manual
  • HyperText
  • Simple
  1. What is an important aspect of an Application Layer protocol like HTTP?
  • How long do we wait before packets are retransmitted?
  • What is the IP address for a domain like www.dr-chuck.com?
  • How much memory does the server need to serve requests?
  • Which application talks first? The client or server?
  1. What are the three parts of this URL (Uniform Resource Locator)?
http://www.dr-chuck.com/page1.htm
  • Host, offset, and page
  • Page, offset, and count
  • Protocol, host, and document
  • Protocol, document, and offset
  • Document, page, and protocol
  1. When you click on an anchor tag in a web page like below, what HTTP request is sent to the server?
  <p>Please click <a href="page1.htm">here</a>.</p>
  • PUT
  • INFO
  • POST
  • GET
  • DELETE

操作题


Autograder 1: Request-Response Cycle

Exploring the HyperText Transport Protocol

You are to retrieve the following document using the HTTP protocol in a way that you can examine the HTTP Response headers.

  • http://data.pr4e.org/intro-short.txt

There are three ways that you might retrieve this web page and look at the response headers:

  • Preferred: Modify the socket1.py program to retrieve the above URL and print out the headers and data. Make sure to change the code to retrieve the above URL - the values are different for each URL.
  • Open the URL in a web browser with a developer console or FireBug and manually examine the headers that are returned.

Autograder 2: Scraping HTML Data with BeautifulSoup

Scraping Numbers from HTML using BeautifulSoup In this assignment you will write a Python program similar to http://www.py4e.com/code3/urllink2.py. The program will use urllib to read the HTML from the data files below, and parse the data, extracting numbers and 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.html
    (Sum=2553)
  • Actual data: http://py4e-data.dr-chuck.net/comments_1577743.html
    (Sum ends with 26)

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 file is a table of names and comment counts. You can ignore most of the data in the file except for lines like the following:

<tr><td>Modu</td><td><span class="comments">90</span></td></tr>
<tr><td>Kenzie</td><td><span class="comments">88</span></td></tr>
<tr><td>Hubert</td><td><span class="comments">87</span></td></tr>

You are to find all the <span> tags in the file and pull out the numbers from the tag and sum the numbers.
Look at the sample code provided. It shows how to find all of a certain kind of tag, loop through the tags and extract the various aspects of the tags.

...
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
   # Look at the parts of a tag
   print 'TAG:',tag
   print 'URL:',tag.get('href', None)
   print 'Contents:',tag.contents[0]
   print 'Attrs:',tag.attrs

You need to adjust this code to look for span tags and pull out the text content of the span tag, convert them to integers and add them up to complete the assignment.
Sample Execution

$ python3 solution.py
Enter - http://py4e-data.dr-chuck.net/comments_42.html
Count 50
Sum 2...

Autograder 3: Following Links with BeautifulSoup

Following Links in Python

In this assignment you will write a Python program that expands on http://www.py4e.com/code3/urllinks.py. The program will use urllib to read the HTML from the data files below, extract the href= vaues from the anchor tags, scan for a tag that is in a particular position relative to the first name in the list, follow that link and repeat the process a number of times and report the last name you find.

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

  • Sample problem: Start at http://py4e-data.dr-chuck.net/known_by_Fikret.html
    Find the link at position 3 (the first name is 1). Follow that link. Repeat this process 4 times. The answer is the last name that you retrieve.
    Sequence of names: Fikret Montgomery Mhairade Butchi Anayah
    Last name in sequence: Anayah
  • Actual problem: Start at: http://py4e-data.dr-chuck.net/known_by_Dyllan.html
    Find the link at position 18 (the first name is 1). Follow that link. Repeat this process 7 times. The answer is the last name that you retrieve.
    Hint: The first character of the name of the last page that you will load is: R

Strategy
The web pages tweak the height between the links and hide the page after a few seconds to make it difficult for you to do the assignment without writing a Python program. But frankly with a little effort and patience you can overcome these attempts to make it a little harder to complete the assignment without writing a Python program. But that is not the point. The point is to write a clever Python program to solve the program.

Sample execution

Here is a sample execution of a solution:

$ python3 solution.py
Enter URL: http://py4e-data.dr-chuck.net/known_by_Fikret.html
Enter count: 4
Enter position: 3
Retrieving: http://py4e-data.dr-chuck.net/known_by_Fikret.html
Retrieving: http://py4e-data.dr-chuck.net/known_by_Montgomery.html
Retrieving: http://py4e-data.dr-chuck.net/known_by_Mhairade.html
Retrieving: http://py4e-data.dr-chuck.net/known_by_Butchi.html
Retrieving: http://py4e-data.dr-chuck.net/known_by_Anayah.html

The answer to the assignment for this execution is “Anayah”.


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

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

相关文章

解决退出重新登陆后提示路由重复问题,在登出时使用

在使用vue-admin-element时&#xff0c;看见 router index.js中底本有这么一个方法导出&#xff0c;发现它在等处的方法中调用的&#xff0c;不太理解他的作用是干嘛的 index.js中 export function resetRouter() {const newRouter createRouter()router.matcher newRouter.…

目录拆分爆破工具

burp开启被动扫描获取到大量target或者爬虫获取到大量target时&#xff0c;经常会出现以下URL的情况&#xff0c;手工无法对目录进行拆分进行简单的目录爆破&#xff0c;所以有了这款工具&#xff0c;思路比较简单&#xff0c;望批评指教。 http://target/path1/path2/path3/* …

时序预测 | MATLAB实现PSO-BiLSTM(粒子群优化双向长短期记忆神经网络)时间序列预测

时序预测 | MATLAB实现PSO-BiLSTM(粒子群优化双向长短期记忆神经网络)时间序列预测 目录 时序预测 | MATLAB实现PSO-BiLSTM(粒子群优化双向长短期记忆神经网络)时间序列预测预测效果基本介绍模型介绍PSO模型BiLSTM模型PSO-BiLSTM模型 程序设计参考资料致谢 预测效果 基本介绍 M…

java之IO流

1、区别 字节流以字节为单位进行读写&#xff0c;可以处理所有类型的数据 字符流以字符为单位进行读写&#xff0c;只能用于处理文本数据 字符流通常使用缓冲区&#xff0c;可以提高读写性能&#xff1b; 而字节流则可以处理二进制数据&#xff0c;可以进行更底层的数据操作。…

《PyTorch深度学习实践》第六讲 逻辑斯蒂回归

b站刘二大人《PyTorch深度学习实践》课程第六讲逻辑斯蒂回归笔记与代码&#xff1a;https://www.bilibili.com/video/BV1Y7411d7Ys?p6&vd_sourceb17f113d28933824d753a0915d5e3a90 分类问题&#xff1a; MNIST数据集&#xff1a;手写数字数据集&#xff1b;6万个训练样本…

vue3+vite+ts视频背景酷炫登录模板【英雄联盟主题】

最近我准备在自己的网站上开发一个博客系统&#xff0c;首先要实现后台登录界面。我选择使用Vue 3 Vite TypeScript框架来构建&#xff0c;下面是针对该主题的详细说明&#xff1a; 在网页中使用视频作为背景图已经相当常见了&#xff0c;而且网上也有很多相关的插件可供使用…

QT Creator上位机学习(四)多线程操作

系列文章目录 文章目录 系列文章目录前言多线程操作多线程创建基本概念接口函数线程类的定义实例 线程同步基础互斥量的线程同步基于QReadWriteLock的线程同步基于QWaitCondition的线程同步基于信号量的线程同步 总结 前言 由于目前时间比较赶&#xff0c;同时还在学习FreeRTO…

ModaHub 魔搭社区:火山方舟是如何解决大模型互信问题的

火山方舟是一个全面的大模型服务平台&#xff0c;通过整合多个大模型公司的产品&#xff0c;为需要大模型的企业提供联系和选择的机会。它不仅提供相关工具和服务&#xff0c;还构建了大模型"安全互信计算架构"&#xff0c;解决了大模型互信的问题。 这个安全互信计算…

【ArcGIS微课1000例】0069:用ArcGIS提取一条线的高程值

本实验讲解用ArcGIS软件,基于数字高程模型DEM提取一条线的高程值并导出。 文章目录 一、加载实验数据二、将线转为折点三、提取折点高程值四、导出高程值五、注意事项【相关阅读】:【GlobalMapper精品教程】060:用dem提取一条线的高程值 一、加载实验数据 本实验使用的数据…

AI创作与游戏开发(三)世界观设计

本文将从实践出发&#xff0c;全方位的在美术&#xff0c;程序&#xff0c;策划, 音乐方面使用AIGC进行游戏开发的辅助创作&#xff0c;来探索AI的上限。 写在前面 不管AI发展到什么地步&#xff0c;要记住一点的是。它只是工具&#xff0c;还是要以我为主&#xff0c;为我所…

Lake Shore475高斯计使用教程

475高斯计具有双排20字符真空荧光显示屏。在正常操作下&#xff0c;显示屏用来显示磁场读数和功能&#xff08;最大、最小值、相对读数等&#xff09;信息。另外也可以被配置为显示被测磁场温度和频率等信息。当设置高斯计参数或功能时&#xff0c;屏幕会显示操作提示和反馈信息…

华为云Could not connect to ‘121.37.92.110‘ (port 22): Connection failed.

今天在使用xshell连接服务器的时候&#xff0c;一直报错&#xff0c;爆的心态都炸了&#xff1a; 在输入主机和密码都正确的情况下&#xff0c;还是连接不上服务器&#xff1a; 后来经过长时间摸索&#xff0c;发现xshell软件要通过镜像系统来操作&#xff0c;而自己买的服务器…

走进人工智能|自动驾驶 迈向无人驾驶未来

前言&#xff1a; 自动驾驶是一种技术&#xff0c;通过使用传感器、人工智能和算法来使车辆能够在不需要人类干预的情况下自主地感知、决策和操作。 文章目录 序言背景核心技术支持传感器技术人工智能与机器学习 迈向无人驾驶未来目前形式领跑人困境和挑战 总结 本篇带你走进自…

【Mysql】X-DOC:Mysql数据库大量数据查询加速(定时JOB和存储过程应用案例)

X-DOC&#xff1a;Mysql数据库大量数据查询加速&#xff08;定时JOB和存储过程应用案例&#xff09; 1、案例背景2、解决思路3、实现方式3.1 开启定时调度功能3.2 创建JOB日志表3.3 创建JOB任务3.4 创建JOB3.5 JOB的维护及查看 4、总结 1、案例背景 在某中台系统中&#xff0c…

基于HTML5的手术室信息管理系统的设计与实现(源码+文档+数据库)

本文通过对现有手术室信息管理系统分析&#xff0c;设计了一套基于 HTML的手术室信息管理系统&#xff0c;实现了患者信息、手术记录及术后随访等功能&#xff0c;提高了手术室工作效率。 本系统实现了患者基本资料的录入及基本信息的查询&#xff0c;提供了术前准备情况及术中…

Android Studio 下载安装教程

在我们下载前&#xff0c;先来了解一下Android的4大组件&#xff1a; 1.活动 2.服务&#xff1a;类似线程&#xff0c;听歌时跳转发信息&#xff0c;后台进行播放音乐&#xff0c;前台交互&#xff0c;后台运行任务 3.广播接收者&#xff1a;【例1】感知充电线充电进度&#xf…

【Spring Boot统一功能处理】统一异常处理,统一的返回格式,@ControllerAdvice简单分析,即将走进SSM项目的大门! ! !

前言: 大家好,我是良辰丫,在上一篇文章中我们已经学习了一些统一功能处理的相关知识,今天我们继续深入学习这些知识,主要学习统一异常处理,统一的返回格式,ControllerAdvice简单分析.&#x1f48c;&#x1f48c;&#x1f48c; &#x1f9d1;个人主页&#xff1a;良辰针不戳 &am…

邀请功能的实现分析

邀请功能 功能分析 场景&#xff1a;项目中出现用户邀请其他用户加入群组的功能 需求&#xff1a;用户点击生成邀请链接可以生成一个url&#xff0c;将这个url分享给其他用户&#xff0c;其他用户点击后对用户登录状态进行校验&#xff0c;校验通过即可加入群组&#xff0c;…

【dubbo triple provider 底层流转】

一、maven依赖 <dependency><groupId>io.netty</groupId><artifactId>netty-codec-http2</artifactId><version>4.1.90.Final</version> </dependency><dependency><groupId>org.apache.dubbo</groupId>&l…

vue3 父子组件传值 记录

最近这个组件之间传值用的较多&#xff0c;我这该死的记性&#xff0c;总给忘记写法&#xff0c;特此记录下 第一种 父传子 补充&#xff1a;LeftView.vue 是父组件&#xff1b; Video.vue 是子组件 第二种 子传父 Video.vue 子组件 第一步 引入&#xff1a; import { de…