Docsity

D522 Python for IT Automation - Final Assessment, Exams of Advanced Education

Toggle sidebar
bg1
D522 Python for IT Automation - Final Assessment
D522 Python for IT Automation - Final Assessment
Pages
Total Marks
Section
Questions
Western Governors University
Python for IT Automation
Python for IT Automation - Final Assessment
Section 1 Multiple Choice
Section 2
Short Answer
Section 3 Long Answer
20 questions
6 questions
3 questions
Name
Student ID
Date
Signature
How to use this exam
1
Set a timer. Practice under real exam conditions! No notes, no AI assistance.
2
When finished, scan the QR code on the last page to submit and see the correct answers
with detailed explanations.
3
Review your mistakes carefully and note down areas that need improvement. Use Studocu
AI to create targeted study materials lik e quizzes, summaries, and study guides.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download D522 Python for IT Automation - Final Assessment and more Exams Advanced Education in PDF only on Docsity!

Pages Total Marks Section Questions

Western Governors University

Python for IT Automation

Python for IT Automation - Final Assessment

Section 1 Multiple^ Choice Section 2 Short^ Answer Section 3 Long^ Answer 20 questions 6 questions 3 questions 40 total marks 30 total marks 30 total marks Name Student ID Date Signature

How to use this exam

1 Set^ a^ timer.^ Practice^ under^ real^ exam^ conditions!^ No^ notes,^ no^ AI^ assistance.

2 When^ finished,^ scan^ the^ QR^ code^ on^ the^ last^ page^ to^ submit^ and^ see^ the^ correct^ answers

with detailed explanations.

3 Review^ your^ mistakes^ carefully^ and^ note^ down^ areas^ that^ need^ improvement.^ Use^ Studocu

AI to create targeted study materials like quizzes, summaries, and study guides.

Section 1 / 3 40 total^ marks Multiple Choice Select the most appropriate answer for each question. Each question is worth 2 marks.

Question 1 2 marks

An administrator is storing a status message in a variable named status. If the code is status = "System Online", which Python data type is being used? A int B bool C float D str

Question 2 2 marks

A script receives a numeric input from a user as a string: value = "10". Which code snippet correctly converts this to an integer and adds 5 to it? A result = str(value) + 5 B result = value + 5 C result = float(value) + "5" D result = int(value) + 5

Question 3 2 marks

You have a list of server names: servers = ["srv1", "srv2"]. Which method should be used to add "srv3" to the end of the existing list? A servers.remove("srv3") B servers.pop("srv3") C servers.insert(0, "srv3") D servers.append("srv3")

Question 7 2 marks

Consider the following function definition: def welcome_user(name="Guest"): What happens if the function is called as welcome_user() without any arguments? A The function prompts the user for input. B The function returns None. C The function uses "Guest" as the default value for name. D The function returns a SyntaxError.

Question 8 2 marks

Which built-in Python function is used to determine the number of items in a list or characters in a string? A len() B dir() C sum() D max()

Question 9 2 marks

A network administrator wants to add new log entries to the end of an existing text file without deleting the current content. Which file mode should be used in the open() function? A 'r' B 'w' C 'a' D 'x' 4 / 13

Question 10 2 marks

An automation script needs to store a fixed sequence of configuration values that should never be changed during the script's execution. Which data structure is most appropriate? A List B Set C Tuple D Dictionary

Question 11 2 marks

Which block in Python is used to catch and handle errors so that a script does not crash unexpectedly? A try/except B if/else C def/return D for/while

Question 12 2 marks

In basic socket programming, which socket method is used by a client to initiate a connection to a remote server and port? A s.bind() B s.accept() C s.connect() D s.listen()

Question 13 2 marks

What will be the value of result after executing: result = 10 % 3? A 3 B 0 C 1 D 3. 5 / 13

Question 18 2 marks

When working with csv.DictReader, how is each row in the CSV file represented? A As a dictionary where column headers are keys. B As a list of strings. C As a tuple. D As a single long string.

Question 19 2 marks

In Python, which Boolean value is returned by the expression bool(0)? A False B Error C True D None

Question 20 2 marks

A script needs to create a unique collection of IP addresses from a long list that contains many duplicates. Which data structure should be used to automatically remove duplicates? A Dictionary B Tuple C Set D List 7 / 13

Section 2 / 3 30 total^ marks Short Answer Provide short, technical answers or code snippets as requested. Each question is worth 5 marks.

Question 21 5 marks

Write a Python code snippet that performs the following tasks:

  1. Creates a list named vlans containing the integers 10, 20, 30, 40, and 50.
  2. Uses slicing to create a new list named sub_vlans that contains only 20, 30, and 40.
  3. Prints sub_vlans.

Question 22 5 marks

You have a dictionary representing a network device: device = {"id": "R1", "ip": "192.168.1.1", "status": "up"}. Write a for loop that iterates through the dictionary using the .items() method and prints each pair in the format: Key: Value.

Question 23 5 marks

Explain the difference between file.read() and file.readlines() when performing file operations in Python. 8 / 13

Section 3 / 3 30 total^ marks Long Answer Provide detailed code solutions and explanations for the following automation scenarios. Each question is worth 10 marks.

Question 27 10 total marks

System Log Data You are tasked with auditing a list of system events. The event logs are stored in a Python list of strings, where each string represents an event and its status (either 'SUCCESS' or 'FAIL'). Example data: logs = ["Login SUCCESS", "Update FAIL", "Backup SUCCESS", "Login FAIL"] A Write a complete Python script to process the logs list from the provided scenario. Your script must:

  1. Initialize a dictionary named audit_results with keys "SUCCESS" and "FAIL", both starting at 0.
  2. Iterate through the logs list.
  3. Check if "SUCCESS" or "FAIL" is in each log entry and increment the corresponding count in the dictionary.
  4. Print the final audit_results dictionary. 10 / 13

Question 28 10 total marks

Network Connectivity Tool You are building a tool to check if a specific management port (Port 80) is open on a target server (IP: 10.0.0.50). You must use the socket module and ensure the script doesn't crash if the connection fails. A Write a Python script to perform the connectivity check described in the scenario. Your script should:

  1. Import the necessary library.
  2. Use a try/except block to attempt a connection to the server.
  3. Create a socket object and set a timeout of 2 seconds.
  4. Attempt to connect to "10.0.0.50" on port 80.
  5. Print "Connection Successful" if it connects, or "Connection Failed" if a socket.error occurs.
  6. Ensure the socket is closed at the end. 11 / 13