Docsity

Automating Real World Tasks with Python Certificate Practice Exam, Exams of Technology

Toggle sidebar
bg1
Automating Real World Tasks with Python
Certificate Practice Exam
**Question 1. Which of the following statements correctly creates a list containing the numbers
1 through 5?**
A) `list = (1,2,3,4,5)`
B) `list = [1,2,3,4,5]`
C) `list = {1,2,3,4,5}`
D) `list = <1,2,3,4,5>`
Answer: B
Explanation: Square brackets `[]` denote a list in Python; parentheses create a tuple, curly
braces a set, and angle brackets are invalid syntax.
**Question 2. What will be the output of `type(True)`?**
A) `<class 'int'>`
B) `<class 'bool'>`
C) `<class 'str'>`
D) `<class 'float'>`
Answer: B
Explanation: The literal `True` is a Boolean value, and its type is `<class 'bool'>`.
**Question 3. Which keyword is used to define an anonymous (lambda) function that adds two
numbers?**
A) `def`
B) `lambda`
C) `func`
D) `anonymous`
Answer: B
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63

Partial preview of the text

Download Automating Real World Tasks with Python Certificate Practice Exam and more Exams Technology in PDF only on Docsity!

Certificate Practice Exam

Question 1. Which of the following statements correctly creates a list containing the numbers 1 through 5? A) list = (1,2,3,4,5) B) list = [1,2,3,4,5] C) list = {1,2,3,4,5} D) list = <1,2,3,4,5> Answer: B Explanation: Square brackets [] denote a list in Python; parentheses create a tuple, curly braces a set, and angle brackets are invalid syntax. Question 2. What will be the output of type(True)? A) <class 'int'> B) <class 'bool'> C) <class 'str'> D) <class 'float'> Answer: B Explanation: The literal True is a Boolean value, and its type is <class 'bool'>. Question 3. Which keyword is used to define an anonymous (lambda) function that adds two numbers? A) def B) lambda C) func D) anonymous Answer: B

Certificate Practice Exam

Explanation: lambda creates a small anonymous function; e.g., lambda x, y: x + y. Question 4. In a Python function, the global keyword is used to: A) Declare a variable that cannot be changed. B) Access a variable defined outside the function’s scope. C) Create a new global variable inside the function. D) Both B and C. Answer: D Explanation: global tells Python that assignments refer to the variable in the module’s global scope, allowing both read and write access. Question 5. What does the following list comprehension produce? [x**2 for x in range(3)] A) [0, 1, 4] B) [1, 4, 9] C) [0, 1, 2] D) [1, 2, 3] Answer: A Explanation: range(3) yields 0,1,2; squaring each gives 0,1,4. Question 6. Which method removes and returns the last item of a list? A) pop() B) remove() C) del() D) extract() Answer: A

Certificate Practice Exam

Answer: B Explanation: os.listdir returns a list of entry names (files and subdirectories) in the given path. Question 10. Which module provides the Path class for object‑oriented filesystem paths? A) os B) sys C) pathlib D) shutil Answer: C Explanation: pathlib.Path offers a modern, OO interface for file system paths. Question 11. What will the following code print? python\ntry:\n 1/0\nexcept ZeroDivisionError:\n print('Error')\nelse:\n print('No error')\n A) Error B) No error C) Nothing D) Raises an exception Answer: A Explanation: The except block catches the ZeroDivisionError and prints “Error”. The else block runs only when no exception occurs. Question 12. Which exception is raised when trying to convert the string 'abc' to an integer using int('abc')? A) ValueError B) TypeError C) KeyError

Certificate Practice Exam

D) AttributeError Answer: A Explanation: The conversion fails because the string does not represent a number, raising ValueError. Question 13. In the logging module, which level is intended for detailed diagnostic information? A) INFO B) WARNING C) DEBUG D) ERROR Answer: C Explanation: DEBUG is the lowest level, used for verbose debugging output. Question 14. Which statement correctly opens a file named data.txt for reading using a context manager? A) with open('data.txt', 'r') as f: B) with open('data.txt', 'w') as f: C) with open('data.txt') as f: D) open('data.txt', 'r') Answer: A Explanation: 'r' specifies read mode; the with statement ensures the file is closed automatically. Question 15. What does the file mode 'a+' do? A) Opens for reading only.

Certificate Practice Exam

A) pd.read_excel('file.xlsx', sheet_name='Sheet1') B) pd.read_csv('file.xlsx', sheet='Sheet1') C) pd.ExcelFile('file.xlsx').load('Sheet1') D) pd.load_excel('file.xlsx', 'Sheet1') Answer: A Explanation: pd.read_excel reads Excel files; sheet_name specifies which sheet to load. Question 19. In openpyxl, which attribute accesses the value of cell B2? A) ws['B2'].value B) ws.B2 C) ws.cell(row=2, column=2).text D) ws.get('B2') Answer: A Explanation: ws['B2'] returns a Cell object; .value retrieves its stored value. Question 20. Which PyPDF2 method extracts text from the first page of a PDF object pdf_reader? A) pdf_reader.getPage(0).extractText() B) pdf_reader.page(0).text() C) pdf_reader.read(0).text D) pdf_reader.extract(0) Answer: A Explanation: getPage(0) returns the first page; extractText() extracts its textual content. Question 21. Which HTTP method is typically used to retrieve data without side effects?

Certificate Practice Exam

A) POST

B) GET

C) PUT

D) DELETE

Answer: B Explanation: GET requests are safe and idempotent, used for reading resources. Question 22. In the requests library, how can you access the JSON body of a response object r? A) r.text B) r.content C) r.json() D) r.data Answer: C Explanation: r.json() parses the response body as JSON and returns a Python object. Question 23. Which BeautifulSoup method finds all <a> tags with class nav-link? A) soup.find_all('a', class_='nav-link') B) soup.select('a.nav-link') C) Both A and B D) Neither A nor B Answer: C Explanation: Both find_all with class_ argument and CSS selector select achieve the same result.

Certificate Practice Exam

Question 27. What is the purpose of the headless mode in a Selenium‑controlled browser? A) To run the browser without a graphical user interface. B) To disable JavaScript execution. C) To open the browser in incognito mode. D) To enable automatic form filling. Answer: A Explanation: Headless mode runs the browser in the background without rendering a window, useful for automation on servers. Question 28. Which HTTP header is commonly used to pass an API key for authentication? A) Authorization B) X-API-Key C) Cookie D) Both A and B (depending on API) Answer: D Explanation: Some APIs expect the key in Authorization: Bearer <token>, others in a custom header like X-API-Key. Question 29. When sending JSON data in a POST request using requests, which argument should you use? A) data= B) json= C) payload= D) body=

Certificate Practice Exam

Answer: B Explanation: The json= parameter automatically serializes the Python object to JSON and sets the appropriate Content-Type header. Question 30. If an API returns a paginated list with a next URL in the JSON response, what is a common way to retrieve all items? A) Loop while next is not null, requesting each URL sequentially. B) Use a single request with limit=all. C) Only request the first page; subsequent pages are cached. D) None of the above. Answer: A Explanation: Pagination requires following the next links until no further page is indicated. Question 31. Which Python standard library module can be used to send an email via an SMTP server? A) smtplib B) email C) imaplib D) poplib Answer: A Explanation: smtplib handles SMTP communication for sending mail. Question 32. To create a multipart email that includes both plain text and HTML alternatives, which class from the email package is most appropriate? A) MIMEText B) MIMEMultipart

Certificate Practice Exam

B) datetime.utcnow() C) datetime.now(timezone.utc) D) Both B and C Answer: D Explanation: datetime.utcnow() returns naive UTC time; datetime.now(timezone.utc) returns an aware UTC datetime. Question 36. Which Python package is commonly used to create isolated environments for project dependencies? A) pip B) venv C) conda D) Both B and C (depending on workflow) Answer: D Explanation: venv (standard library) and conda (Anaconda) both provide environment isolation. Question 37. In a requirements.txt file, how would you specify that version 2.1.0 of package requests is required? A) requests==2.1.0 B) requests>=2.1.0 C) requests~=2.1.0 D) requests=2.1.0 Answer: A Explanation: == pins the package to the exact version.

Certificate Practice Exam

Question 38. Which command installs the packages listed in requirements.txt using pip? A) pip install - r requirements.txt B) pip install requirements.txt C) pip get - r requirements.txt D) pip download requirements.txt Answer: A Explanation: -r tells pip to read the file and install each listed requirement. Question 39. When using Docker to containerize a Python app, which file defines the build instructions? A) docker-compose.yml B) Dockerfile C) requirements.txt D) setup.py Answer: B Explanation: Dockerfile contains the steps to build a Docker image. Question 40. Which of the following is a valid way to schedule a Python script to run daily at 2 AM on a Linux system? A) Add 0 2 * * * /usr/bin/python3 /path/script.py to the crontab. B) Use at 02:00 /path/script.py. C) Place a shortcut in the Desktop folder. D) None of the above. Answer: A Explanation: Crontab syntax minute hour day month weekday command schedules recurring jobs; 0 2 * * * means 02:00 daily.

Certificate Practice Exam

Explanation: A set removes duplicate elements, resulting in {1, 2, 3}. Question 44. Which built‑in function can be used to convert a string '123' to an integer? A) int('123') B) float('123') C) str('123') D) bool('123') Answer: A Explanation: int() parses the string and returns an integer. Question 45. In a function definition def foo(a, b=5, *args, **kwargs):, which parameter collects extra positional arguments? A) a B) b C) *args D) **kwargs Answer: C Explanation: *args gathers any additional positional arguments into a tuple. Question 46. Which of the following statements about the global keyword is false? A) It allows a function to modify a variable defined at module level. B) It creates a new global variable if the name does not exist. C) It can be used inside a class method to affect class attributes. D) It must be declared before the variable is used inside the function. Answer: C

Certificate Practice Exam

Explanation: global only works with module‑level variables, not with class attributes (which require self or cls). Question 47. What will be the output of print(bool('False'))? A) False B) True C) 0 D) Raises a ValueError Answer: B Explanation: Any non‑empty string evaluates to True, regardless of its textual content. Question 48. Which method of a dict returns a view object of its keys? A) dict.keys() B) dict.values() C) dict.items() D) dict.get() Answer: A Explanation: keys() provides a dynamic view of the dictionary’s keys. Question 49. If you need to ensure that a block of code runs whether or not an exception occurs, which construct should you use? A) finally B) else C) except D) raise

Certificate Practice Exam

C) Both A and B (assuming lines already contain newline characters for A). D) Neither A nor B. Answer: C Explanation: writelines writes each element as‑is; if lines lack newlines, option B ensures proper line separation. Question 53. When reading a CSV file with csv.reader, which argument must be supplied to correctly handle files encoded in UTF‑8 with a BOM? A) encoding='utf- 8 - sig' B) encoding='utf-8' C) newline='' D) No special argument is needed. Answer: A Explanation: utf- 8 - sig removes the Byte Order Mark automatically. Question 54. Which of the following pandas functions merges two DataFrames df1 and df2 on column id using an inner join? A) pd.concat([df1, df2], on='id') B) pd.merge(df1, df2, on='id', how='inner') C) df1.join(df2, on='id') D) df1.append(df2, on='id') Answer: B Explanation: pd.merge with how='inner' performs an inner join on the specified key. Question 55. In openpyxl, how would you set the width of column A to 20 characters? A) ws.column_dimensions['A'].width = 20

Certificate Practice Exam

B) ws.column_dimensions['A'].set_width(20) C) ws.set_column('A', 20) D) ws.column('A').width = 20 Answer: A Explanation: column_dimensions provides a mapping where you can assign the width attribute. Question 56. Which method of a PdfFileWriter object adds a new page to the PDF? A) addPage(page) B) insert_page(page) C) append(page) D) write_page(page) Answer: A Explanation: addPage appends a PageObject to the writer. Question 57. What does the HTTP status code 429 indicate? A) Not Found B) Unauthorized C) Too Many Requests (rate limiting) D) Internal Server Error Answer: C Explanation: 429 is returned when the client has sent too many requests in a given amount of time. Question 58. In the requests library, which parameter controls the maximum time to wait for a response?