All Weeks Using Python to Access Web Data Quiz Answers
Using Python to Access Web Data Week 1 Quiz Answers
Quiz: Regular Expressions
Q1. Which of the following best describes “Regular Expressions”?
- The way Python handles and recovers from errors that would otherwise cause a traceback
- A way to calculate mathematical values paying attention to operator precedence
- A way to solve Algebra formulas for the unknown value
- A small programming language unto itself
Q2. Which of the following is the way we match the “start of a line” in a regular expression?
- correcr answer ^
- str.startswith()
- \linestart
- String.startsWith()
- variable[0:1]
Q3. What would the following mean in a regular expression? [a-z0-9]
- Match anything but a lowercase letter or digit
- Match a lowercase letter or a digit
- Match any number of lowercase letters followed by any number of digits
- Match an entire line as long as it is lowercase letters or digits
- Match any text that is surrounded by square braces
Q4. What is the type of the return value of the re.findall() method?
- A boolean
- A single character
- An integer
- A list of strings
- A string
Q5. What is the “wild card” character in a regular expression (i.e., the character that matches any character)?
- *
- +
- ?
- ^
- $
- correct answer .
Q6. What is the difference between the “+” and “*” character in regular expressions?
- The “+” matches at least one character and the “*” matches zero or more characters
- The “+” matches upper case characters and the “*” matches lowercase characters
- The “+” matches the beginning of a line and the “*” matches the end of a line
- The “+” matches the actual plus character and the “*” matches any character
- The “+” indicates “start of extraction” and the “*” indicates the “end of extraction”
Q7. What does the “[0-9]+” match in a regular expression?
- Any number of digits at the beginning of a line
- One or more digits
- Zero or more digits
- Any mathematical expression
- Several digits followed by a plus sign
Q8. What does the following Python sequence print out?
x = 'From: Using the : character'
y = re.findall('^F.+:', x)
print(y)
- :
- From:
- [‘From:’]
- [‘From: Using the :’]
- ^F.+:
Q9. What character do you add to the “+” or “*” to indicate that the match is to be done in a non-greedy manner?
- ++
- $
- **
- ^
- correct answer ?
- \g
Q10. Given the following line of text:
From [email protected] Sat Jan 5 09:14:16 2008
What would the regular expression ‘\S+?@\S+’ match?
- From
- [email protected]
- \@\
- marquard@uct
- [email protected]
Using Python to Access Web Data Week 2 Quiz Answers
Quiz: Networks and Sockets
Q1. 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
- DECNET
- The Request/Response Cycle
- Internet Protocol (IP)
- IMAP
Q2. What separates the HTTP headers from the body of the HTTP document?
- A blank line
- A less-than sign indicating the start of an HTML tag
- Four dashes
- X-End-Header: true
Q3. What must you do in Python before opening a socket?
- import tcp-socket
- open socket
- import tcp
- _socket = true
- import socket
Q4. In a client-server application on the web using sockets, which must come up first?
- server
- client
- it does not matter
Q5. Which of the following is most like an open socket in an application?
- An “in-progress” phone conversation
- Fiber optic cables
- The wheels on an automobile
- The chain on a bicycle
- The ringer on a telephone
Q6. What does the “H” of HTTP stand for?
- HyperText
- wHolsitic
- Simple
- Hyperspeed
- Manual
Q7. 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?
Q8. What are the three parts of this URL (Uniform Resource Locator)?
http://www.dr-chuck.com/page1.htm
- Page, offset, and count
- Protocol, document, and offset
- Protocol, host, and document
- Host, offset, and page
- Document, page, and protocol
Q9. 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>
- GET
- POST
- PUT
- DELETE
- INFO
Q10. Which organization publishes Internet Protocol Standards?
- LDAP
- SCORM
- IMS
- SIFA
- IETF
Using Python to Access Web Data Week 3 Quiz Answers
Quiz :Reading Web Data From Python
Q1. Which of the following Python data structures is most similar to the value returned in this line of Python:
x = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
1 point
- list
- regular expression
- file handle
- socket
- dictionary
Q2. In this Python code, which line actually reads the data?
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close()
- mysock.recv()
- socket.socket()
- mysock.close()
- mysock.connect()
- mysock.send()
Q3. Which of the following regular expressions would extract the URL from this line of HTML:
<p>Please click <a href="http://www.dr-chuck.com">here</a></p>
- href=”(.+)”
- href=”.+”
- http://.*
- <.*>
Q4. In this Python code, which line is most like the open() call to read a file:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close()
- mysock.connect()
- import socket
- mysock.recv()
- mysock.send()
- socket.socket()
Q5. Which HTTP header tells the browser the kind of document that is being returned?
- HTML-Document:
- Content-Type:
- Metadata:
- Document-Type:
- ETag:
Q6. What should you check before scraping a web site?
- That the web site supports the HTTP GET command
- That the web site returns HTML for all pages
- That the web site only has links within the same site
- That the web site allows scraping
Q7. What is the purpose of the BeautifulSoup Python library?
- It allows a web site to choose an attractive skin
- It optimizes files that are retrieved many times
- It repairs and parses HTML to make it easier for a program to understand
- It builds word clouds from web pages
- It animates web operations to make them more attractive
Q8. What ends up in the “x” variable in the following code:
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
x = soup('a')
- A list of all the anchor tags (<a..) in the HTML from the URL
- True if there were any anchor tags in the HTML from the URL
- All of the externally linked CSS files in the HTML from the URL
- All of the paragraphs of the HTML from the URL
Q9. What is the most common Unicode encoding when moving data between systems?
- UTF-64
- UTF-8
- UTF-16
- UTF-32
- UTF-128
Q10. What is the ASCII character that is associated with the decimal value 42?
- !
- ^
- correct answer *
- +
- /
Q11. What word does the following sequence of numbers represent in ASCII:
108, 105, 110, 101
- lost
- tree
- ping
- func
- line
Q12. How are strings stored internally in Python 3?
- EBCDIC
- ASCII
- Byte Code
- Unicode
- UTF-8
Q13. When reading data across the network (i.e. from a URL) in Python 3, what method must be used to convert it to the internal format used by strings?
- trim()
- upper()
- decode()
- encode()
- find()
Using Python to Access Web Data Week 4 Quiz Answers
Quiz: eXtensible Markup Language
Q1. What is the name of the Python 2.x library to parse XML data?
- xml.json
- xml.etree.ElementTree
- xml-misc
- xml2
Q2. Which of the following are not commonly used serialization formats?
- Dictionaries
- XML
- JSON
- HTTP
- TCP
Q3. 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>
- person
- name
- people
- Noah
- phone
Q4. In the following XML, which are attributes?
<person>
<name>Chuck</name>
<phone type="intl">
+1 734 303 4456
</phone>
<email hide="yes" />
</person>
- name
- hide
- type
- person
Q5. 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>
- e
- b
- c
- a
Q6. 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>
- b
- Z
- e
- Y
- a
Q7. What is the purpose of XML Schema?
- To establish a contract as to what is valid XML
- To transfer XML data reliably during network outages
- To compute SHA1 checksums on data to make sure it is not modified in transit
- A Python program to tranform XML files
Q8. 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?
- Age
- lastname
- age
- person
- dateborn
Q9. What does the “Z” mean in this representation of a time:12002-05-30T09:30:10Z
- This time is in the UTC timezone
- The hours value is in the range 0-12
- The local timezone for this time is New Zealand
- This time is Daylight Savings Time
Q10. Which of the following dates is in ISO8601 format?
- 2002-May-30
- May 30, 2002
- 2002-05-30T09:30:10Z
- 05/30/2002
Using Python to Access Web Data Week 5 Quiz Answers
Quiz: REST, JSON, and APIs
Q1. Who is credited with the REST approach to web services?
- Vint Cerf
- Bjarne Stroustrup
- Roy Fielding
- Leonard Klienrock
- Daphne Koller
Q2. What Python library do you have to import to parse and handle JSON?
- import re
- ElementTree
- import json
- BeautifulSoup
Q3. Which of the following is a web services approach used by the Twitter API?
- CORBA
- SOAP
- REST
- XML-RPC
Q4. What kind of variable will you get in Python when the following JSON is parsed:
{ "id" : "001",
"x" : "2",
"name" : "Chuck"
}
- A list of tuples
- A tuple with three items
- A dictionary with three key / value pairs
- A list with three items
- A list with six items
Q5. Which of the following is not true about the service-oriented approach?
- An application makes use of the services provided by other applications
- Standards are developed where many pairs of applications must work together
- An application runs together all in one place
- Web services and APIs are used to transfer data between applications
Q6. Which of these two web service approaches is preferred in most modern service-oriented applications?
- SOAP – Simple Object Access Protocol
- REST – Representational state transfer
Q7. What library call do you make to append properly encoded parameters to the end of a URL like the following:
//maps.googleapis.com/maps/api/geocode/json?sensor=false&address=Ann+Arbor%2C+MI
- urllib.parse.urlencode()
- re.match()
- urllib.urlcat()
- re.encode()
Q8. 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 cannot use the API until you respond to an email that contains a survey question
- Your application starts to perform very slowly
Q9. What protocol does Twitter use to protect its API?
- SOAP
- SHA1-MD5
- PKI-HMAC
- Java Web Tokens
- OAuth
- WS*Security
Q10. What header does Twitter use to tell you how many more API requests you can make before you will be rate-limited?
- content-type
- x-rate-limit-remaining
- x-max-requests
- x-request-count-down
Get All Course Quiz Answers of Python for Everybody Specialization
Course 01: Programming for Everybody (Getting Started with Python)
Course 02: Python Data Structures
Course 03: Using Python to Access Web Data
Course 04: Using Databases with Python
Course 05: Capstone: Retrieving, Processing, and Visualizing Data with Python