Module 5: APIs and Data Collection

Looking for ‘python for data science ai & development module 5 answers‘?

In this post, I provide accurate answers and detailed explanations for Module 5: APIs and Data Collection of Course 4: Python for Data Science, AI & Development IBM Generative AI Engineering Professional Certificate

Whether you’re preparing for quizzes or brushing up on your knowledge, these insights will help you master the concepts effectively. Let’s dive into the correct answers and detailed explanations for each question.

Practice Quiz: Simple APIs

Practice Assignment

1. What does API stand for?

  • Application Programming Interaction
  • Automatic Program Interaction
  • Application Process Interface
  • Application Programming Interface ✅

Explanation:
An API (Application Programming Interface) is a set of definitions and protocols that allow different software applications to communicate with each other. It defines the methods and data formats that programs can use to request and exchange information.

2. Which data format is commonly found in the HTTP message for API requests?

  • YAML
  • JSON ✅
  • XML
  • HTML

Explanation:
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write, and for machines to parse and generate. It is widely used in API requests and responses because it is simple and efficient. Other formats like XML are also used but less commonly compared to JSON in modern APIs.

3. What is the primary purpose of an API?

  • To connect and enable communication between software applications. ✅
  • To provide security to web applications.
  • To design user interfaces for mobile applications.
  • To handle server-side database operations.

Explanation:
The main purpose of an API is to act as a bridge between different software systems, enabling them to share data and functionality seamlessly. For instance, APIs allow a mobile app to fetch data from a server or a third-party service to integrate its features into your application.

4. The chart used to plot the cryptocurrency data in the lab is a

  • Line Chart
  • Point and Figure Chart
  • Pole Chart
  • Candlestick Chart ✅

5. What information are we trying to find for each day in the lab for the chart?

  • Open (Last), High (Max), Low (Min), Close (First)
  • Open (First), High (Max), Low (Min), Close (Last) ✅
  • Open (Max), High (First), Low (Last), Close (Min)
  • Open (Min), High (First), Low (Max), Close (Last)

Practice Quiz: REST APIs, Web Scraping, and Working with Files

Practice Assignment

6. What is the function of "GET" in HTTP requests?

  • Returns the response from the client to the requestor
  • Carries the request to the client from the requestor ✅
  • Sends data to create or update a resource
  • Deletes a specific resource

Explanation:
The GET method is used in HTTP requests to retrieve data from a server. It is a safe and idempotent method, meaning it doesn’t modify any resources on the server. It simply fetches and returns the requested data to the client.

7. What does URL stand for?

  • Uniform Request Location
  • Uniform Resource Locator ✅
  • Unilateral Resistance Locator
  • Uniform Resource Learning

Explanation:
A URL (Uniform Resource Locator) is the address used to access resources on the internet, such as web pages, images, and videos. It specifies the location of the resource and the protocol to use when accessing it (e.g., https://example.com).

8. What does the file extension “csv” stand for?

  • Comma Separated Values ✅
  • Comma Separation Valuations
  • Common Separated Variables
  • Comma Serrated Values

Explanation:
A CSV (Comma Separated Values) file is a plain text format where data is organized in rows, and individual values within each row are separated by commas. It is commonly used for exchanging data between applications like spreadsheets and databases.

9. What is webscraping?

  • The process to display all data within a URL
  • The process to describe communication options
  • The process to extract data from a particular website ✅
  • The process to request and retrieve information from a client

Explanation:
Web scraping involves using software tools or scripts to automatically extract data from websites. This is often used for data analysis, price comparison, or collecting information for research purposes.

Module 5 Graded Quiz: APIs and Data Collection

Graded Assignment

10. What are the three parts to a response message?

  • HTTP headers, blank line, and body
  • Bookmarks, history, and security
  • Start or status line, header, and body ✅
  • Encoding, body, and cache

Explanation:
A typical HTTP response message consists of:

  1. Start or status line (e.g., HTTP/1.1 200 OK), which indicates the status of the response.
  2. Header, which includes metadata such as content type and server information.
  3. Body, which contains the actual data requested, such as HTML or JSON.

11. What is the purpose of this line of code "table_row=table.find_all(name=’tr’)" used in webscraping?

  • It will find all of the data within the table marked with a tag “tr” ✅
  • It will find all of the data within the table marked with a tag “p
  • It will find all of the data within the table marked with a tag “h1
  • It will find all of the data within the table marked with a tag “a

Explanation:
The find_all method in Beautiful Soup searches for all occurrences of a specific HTML tag within a web page. Here, it looks for all rows (tr tags) within a table and assigns them to the table_row variable.

12. In what data structure do HTTP responses generally return?

  • Tuples
  • Lists
  • Nested Lists
  • JSON ✅

Explanation:
JSON (JavaScript Object Notation) is the most common format for returning data in HTTP responses. It organizes information as key-value pairs, making it easy to parse and use in web applications.

13. The Python library we used to plot the chart in the lab is

  • Pandas
  • Plotly
  • MatPlotLib ✅
  • PyCoinGecko

Explanation:
Matplotlib is a widely used Python library for creating static, interactive, and animated visualizations. It is highly versatile for generating various types of plots, including line charts, bar graphs, and scatter plots.

14. The Python library we used to plot the chart in the lab is

  • Table caption
  • Table cell data ✅
  • Table description
  • Table row

Explanation:
In HTML, the <td> tag is used to define cells within a table row (<tr>). Each <td> element represents one piece of data in a table.

Final Exam for the Course

Graded Assignment

15. In Python, which data type represents text?

  • complex
  • str ✅
  • float
  • int

Explanation:
The str data type is used in Python to represent textual data.

16. Given the string Name="ABCDE", what outcome does the operation Name.find("B") produce?

  • 2
  • 0
  • 1 ✅
  • 5

Explanation:
The find() method returns the index of the first occurrence of the specified character. Here, "B" is at index 1.

17. What following code segment would produce an output of “0”?

  • 2//1
  • 2/1
  • 1/2 ✅
  • 1//2

Explanation:
The // operator performs floor division, returning only the integer part of the result. 1 // 2 equals 0.

18. Complete the statement. Dictionary items can be:

  • A collection of strings only
  • Stored in duplicate keys
  • Numerous data types ✅
  • Only one data type

Explanation:
Dictionaries in Python can store different data types as values, but keys must be unique.

19. What will this code segment “A[0]” obtain from a list or tuple?

  • The second element of a list or tuple
  • The third element of a list or tuple
  • The last element of a list or tuple
  • The first element of a list or tuple ✅

Explanation:
Indexing in Python starts from 0, so A[0] retrieves the first element.

20. What outcome does the operation '1:2,3:4'.split(':') produce?

  • [‘1,2,3,4’]
  • [‘1’, ‘2,3’, ‘4’] ✅
  • [‘1,2’, ‘3,4’]
  • [‘1’, ‘2’, ‘3’, ‘4’]

Explanation:
The split(':') method splits the string at each occurrence of ':'.

21. What code segment cast list “B” to the set “b”?

  • b.set()
  • b=set(B) ✅
  • b = B.set()
  • b=B.dict()

Explanation:
The set() function converts a list to a set, removing duplicates.

22. For the code shared below, what value of x will produce the output “How are you?”? [Select three]

How are you?

if(x!=1):
print('How are you?')
else:
print('Hi')

  • x = 6 ✅
  • x = 1
  • x = 0
  • x = “7”

Explanation:
The condition if (x != 1) is true for all values of x except 1.

23. Which statement ensures the execution of the remaining code regardless of the outcome?

  • While
  • If
  • Finally ✅
  • For

Explanation:
The finally block is always executed after a try block, regardless of exceptions.

24. When slicing in Python what does the “0” in this statement [0:2] specify?

  • It specifies the position to start the slice ✅
  • It specifies the step of the slicing
  • It specifies the position to end the slice

25. If var = “01234567” what Python statement would print out only the odd elements?

  • print(var[1::2]) ✅
  • print(var[3::1]) 
  • print(var[2::2])

26. Consider the string Name=”EMILY”, what statement would return the index of 0?

  • Name.find(“E”) ✅
  • Name.find(“L”)
  • Name.find(“I”)

27. In Python what data type is used to represent text and not numbers?

  • int
  • str ✅
  • float

28. What is the result of the following code segment: int(3.99)

  • 3 ✅
  • 3.99
  • 4

29. What following code segment would produce an output of “0.5”?

  • 1/2 ✅
  • 1//2

30. In Python 3 what following code segment will produce an int?

  • 2//3 ✅
  • 1/2

31. How many identical keys can a dictionary have ?

  • 100000000
  • 0 ✅
  • 3

32. What does the index of “1” correspond to in a list or tuple?

  • the third
  • The first element
  • The second element ✅

33. What is the result of the following operation: '1,2,3,4'.split(',') ?

  • ‘1’,’2′,’3′,’4′
  • [‘1′,’2′,’3′,’4’] ✅
  • (‘1′,’2′,’3′,’4’)
  • ‘1234’

34. Tuples are:

  • Not indexed
  • Mutable
  • Not mutable ✅
  • Unordered

35. What is a collection that is unordered, unindexed and does not allow duplicate members?

  • Set ✅
  • Tuple
  • List

36. If x=1 what will produce the below output?

Hi

Mike

  • if(x==1):

    print(‘Hello’)

    else:

    print(‘Hi’)

    print(‘Mike’)

  • if(x!=1):

    print(‘Hello’)

    else:

    print(‘Hi’)

    print(‘Mike’) ✅

  • if(x!=1):

    print(‘Hi’)

    else:

    print(‘Hello’)

    print(‘Mike’)

37. What statement will execute the remaining code no matter the end result?

  • If
  • For
  • While
  • Finally ✅

38. What add function would return ‘2’ ?

  • def add(x): return(x+x) add(‘1’)
  • def add(x): return(x+x) add(1) ✅
  • def add(x): return(x+x+x) add(‘1’)

Explanation:
The function doubles the argument, returning 2 when 1 is passed.

39. What code segment would output the following?

2

Explanation:
This loop prints 2 when the condition i == 2 is met.

40. What is the rectangle's height in the Rectangle class?

class Rectangle(object):
def __init__(self,width=2,height =3,color='r'):
self.height=height
self.width=width
self.color=color
def drawRectangle(self):
import matplotlib.pyplot as plt
plt.gca().add_patch(plt.Rectangle((0, 0),self.width, self.height
,fc=self.color))
plt.axis('scaled') plt.show()

  • 3 ✅
  • 2
  • ‘r’
  • 0

Explanation:
The default value of height in the class constructor is 3.

41. What function returns a sorted list?

  • sorted() ✅
  • lower()
  • sort()
  • find()

Explanation:
The sorted() function returns a new, sorted list.

42. What outcome do the following lines of code produce?

a=np.array([0,1,0,1,0])

b=np.array([1,0,1,0,1])

a+b

  • array([0, 0, 0, 0, 0])
  • 0
  • array([1, 0, 1, 0, 1])
  • array([1, 1, 1, 1, 1]) ✅

Explanation:
Element-wise addition is performed between the arrays.

43. What outcome do the following lines of code produce?

a=np.array([1,1,1,1,1])
a+10

  • array([1,1,1,1,1])
  • array([0,0,0,0,0])
  • array([10,10,10,10,10])
  • array([11, 11, 11, 11, 11]) ✅

Explanation:
Adding 10 to each element of the array results in [11, 11, 11, 11, 11].

44. Which of the following is a two-dimensional data structure by default?

  • Pandas Series
  • Pandas Dataframe ✅
  • Numpy List
  • Numpy array

Explanation:
A Pandas DataFrame is inherently a 2D data structure.

45. Given the file object named file1, which of the following codes prints the first 2 lines of the content in it?

  • file1.readline(4)
  • for n in range(0, 2):
    print(file1.readline()) ✅
  • file1.readline(2)
  • file1.read(2)

Explanation:
The loop reads and prints the first two lines.

46. What mode will write text at the end of the existing text in a file?

  • Read binary “rb”
  • Read “r”
  • Write “w”
  • Append “a” ✅

Explanation:
The a mode appends data to an existing file.

47. What is scheme, internet address and route a part of?

  • API
  • Text file
  • Error message
  • URL ✅

Explanation:
A URL consists of a scheme (e.g., https), an address (e.g., www.example.com), and a route (e.g., /path).

48. Using which of the following functions, can you extract a table from a webpage directly?

  • pandas.read_html() ✅
  • pandas.read_csv()
  • pandas.read_xml()
  • pandas.read_json()

Explanation:
The read_html() function retrieves all tables from a webpage as a list of DataFrames.

49. What is the output for the below line of code?

A=[8,5,2] for a in A: print(12-a)

  • 8

    5

    2

  • 4

    7

    10 ✅

  • 888888888888

    555555555555

    222222222222

50. What is the output of the following?

for i in range(1,5): if (i!=2): print(i)

  • 1

    2

    3

    4

  • 1

    3

    4 ✅

  • 2

51. Consider the class Rectangle, what are the data attributes?

class Rectangle(object):
def __init__(self,width=2,height =3,color='r'):
self.height=height
self.width=width
self.color=color
def drawRectangle(self):
import matplotlib.pyplot as plt
plt.gca().add_patch(plt.Rectangle((0, 0),self.width,
self.height ,fc=self.color))
plt.axis('scaled')
plt.show()

  • drawRectangle
  • __init__
  • self.height, self.width,self.color ✅

52. What is the result of the following lines of code?

a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a/b

  • array([0.1, 1.0, 0.1, 1.0, 0.1])
  • array([1, 1, 1, 1, 1])
  • Division by zero error

53. What is the result of the following lines of code?

a=np.array([1,1,1,1,1]) a+10

  • array([10,10,10,10,10])
  • array([1,1,1,1,1])
  • array([11, 11, 11, 11, 11]) ✅

54. What does the following line of code select along with the headers ‘Artist’, ‘Length’ and ‘Genre’ from the dataframe df?

y=df[['Artist','Length','Genre']]

  • The entire dataframe
  • Rows
  • Columns ✅

55. Consider the file object: File1. How would you print the first two lines of text?

  • file1.readline(4)
  • for n in range(0,2): print(file1.readline()) ✅

56. Consider the following line of code:

with open("Example.txt","a") as file1:

What mode is the file object in?

  • append ✅
  • read
  • write

57. What is the extraction of data from a website?

  • Web crawling
  • Data mining
  • Webscraping ✅

Related contents:

You might also like:

Leave a Reply