Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Viewing 0 reply threads
  • Author
    Posts
    • #906
      Abhishek TyagiAbhishek Tyagi
      Keymaster

      1. 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’)

      Answer-

      file handle

       

       

      2. In this Python code, which lines read 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()

      Answer-

      mysock.recv()

       

       

      3.Which of the following regular expressions would extract the URL from this line of HTML:
      Please click ” http://www.dr-chuck.com
      Answer-

      href=”(.+)”

       

       

      4. 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()

      Answer-

      mysock.connect()

       

       

      5. Which HTTP header tells the browser the kind of document that is being returned?
      Answer-

      Content-Type:

       

       

      6. What should you check before scraping a web site?
      Answer-

      That the web site allows scraping

       

       

      7. What is the purpose of the BeautifulSoup Python library?
      Answer-
      It repairs and parses html to make it easier for a program to understand

       

       

      8. 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’)
      Answer-

      A list of all the anchor tags (<a..) in the HTML from the URL

       

       

      9. What is the most common Unicode encoding when moving data between systems?
      Answer-

      UTF-8

       

       

      10. What is the decimal (Base-10) numeric value for the upper case letter “G” in the ASCII character set?
      Answer-

      71

       

       

      11. What word does the following sequence of numbers represent in ASCII:
      108, 105, 110, 101
      Answer-

      line

       

       

      12. How are strings stored internally in Python 3?
      Answer-

      Unicode

       

       

      13. 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?
      Answer-

      decode()

       

       

      14. What is the ASCII character that is associated with the decimal value 42?
      Answer-

      *

Viewing 0 reply threads
  • You must be logged in to reply to this topic.