Automate Cybersecurity Tasks with Python | Week 3

Week 3 – Work with strings and lists

Course Name: Automate Cybersecurity Tasks with Python

Course Link: Automate Cybersecurity Tasks with Python

These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Test your knowledge: Work with strings

Q1. Which of the following statements correctly describe strings? Select all that apply.

  • Strings must be placed in quotation marks (” “).
  • Strings are immutable.
  • Strings must be placed in brackets ([ ]).
  • Strings cannot contain numeric characters.

Answer: Strings must be placed in quotation marks (” “).
Strings are immutable.


Q2. What does the following code return?
device_id = “uu0ktt0vwugjyf2”
print(device_id[2:5])

  • “u0k”
  • “0kt”
  • “u0kt”
  • “0ktt”

Answer: “0kt”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q3. What does the following code display?
device_id = “Tj1C58Dakx”
print(device_id.lower())

  • “Tj1C58Dakx”
  • “TJ1C58DAKX”
  • “tj1C58Dakx”
  • “tj1c58dakx”

Answer: “tj1c58dakx”


Q4. You want to find the index where the substring “192.168.243.140” starts within the string contained in the variable ip_addresses. Complete the Python code to find and display the starting index. (If you want to undo your changes to the code, you can click the Reset button.)

Answer:
ip_addresses = "192.168.140.81, 192.168.109.50, 192.168.243.140"
###YOUR CODE HERE###
print(ip_addresses.index("192.168.243.140"))

What index does the substring “192.168.243.140” start at?

  • 34
  • 33
  • 31
  • 32

Answer: 32


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Test your knowledge: Work with lists and develop algorithms

Q1. Review the following code:
my_list = [“a”, “b”, “c”, “d”]
my_list[2] = 4
print(my_list)
What will it display?

  • [“a”, “b”, “4”, “d”]
  • [“a”, “b”, 4, “d”]
  • [“a”, 4, “c”, “d”]
  • An error message

Answer: [“a”, “b”, 4, “d”]


Q2. You are working with the list [“cwvQSQ”,”QvPvX5″,”ISyT3a”,”S7vgN0″]. Its elements represent machine IDs, and the list is stored in a variable named machine_ids. Which line of code will add the ID of “yihhLL” at index 3?

  • machine_ids.insert(3,”yihhLL”)
  • machine_ids.append(“yihhLL”)
  • machine_ids.insert(“yihhLL”,3)
  • machine_ids.append(“yihhLL”,3)

Answer: machine_ids.insert(3,”yihhLL”)


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q3. Which line of code will remove the username “tshah” from the following list?
access_list = [“elarson”, “bmoreno”, “tshah”, “sgilmore”]

  • access_list[“tshah”].remove()
  • access_list.remove(3)
  • access_list.remove(“tshah”)
  • access_list.remove(2)

Answer: access_list.remove(“tshah”)


Q4. As a security analyst, you are responsible for developing an algorithm that automates removing usernames that match specific criteria from an access list. What Python components would help you implement this? Select three answers.

  • A for loop that iterates through the usernames in the access list
  • The .remove() method
  • An if statement that compares a username to the criteria for removal
  • The .append() method

Answer: A for loop that iterates through the usernames in the access list
The .remove() method
An if statement that compares a username to the criteria for removal


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz

See also  Automate Cybersecurity Tasks with Python | Week 1

Test your knowledge: Regular expressions

Q1. Which regular expression symbol represents one or more occurrences of a specific character?

  • *
  • \d
  • \w
  • +

Answer: +


Q2. As a security analyst, you are responsible for finding employee IDs that end with the character and number sequence “a6v”. Given that employee IDs consist of both numbers and alphabetic characters and are at least four characters long, which regular expression pattern would you use?

  • “a6v”
  • “\wa6v”
  • “\w+a6v”
  • “\w*a6v”

Answer: “\w+a6v”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q3. You have imported the re module into Python with the code import re. You want to use the findall() function to search through a string. Which function call enables you to search through the string contained in the variable text in order to return all matches to a regular expression stored in the variable pattern?

  • re.findall(text, pattern)
  • findall(pattern, text)
  • re.findall(pattern, text)
  • findall(text, pattern)

Answer: re.findall(pattern, text)


Q4. Which of the following strings would Python return as matches to the regular expression pattern “\w+”? Select all that apply.

  • “FirstName”
  • “#name”
  • “”
  • “3”

Answer: “FirstName”
“3”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Module 3 challenge

Q1. Which line of code converts the integer 7 to a string?

  • str(“7”)
  • str(7)
  • string(7)
  • string(“7”)

Answer: str(7)


Q2. Which line of code returns a copy of the string “HG91AB2” as “hg91ab2”?

  • print(“HG91AB2”.lower())
  • print(“HG91AB2″(lower))
  • print(lower.”HG91AB2″())
  • print(lower(“HG91AB2”))

Answer: print(“HG91AB2”.lower())


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q3. What is the index of the character “4” in the string “h204D3921”?

  • 2
  • 3
  • 4
  • 5

Answer: 3


Q4. You need to take a slice from an employee ID. Specifically, you must extract the characters with indices of 3, 4, 5, and 6. Complete the Python code to take this slice and display it. (If you want to undo your changes to the code, you can click the Reset button.)

Answer:
employee_id = "w237x430y567"
###YOUR CODE HERE###
print(employee_id [3:7])

What string does the code output?

  • “x430”
  • “37×4”
  • “7×43”
  • “237x”

Answer: “7×43”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q5. What is the output of the following code?
list1 = [1, 2, 3]
list2 = [“a”, “b”, “c”]
print(list1 + list2)

  • [1, 2, 3, “a”, “b”, “c”]
  • An error message
  • [1, “a”, 2, “b”, 3, “c”]
  • [6, “abc”]

Answer: [1, 2, 3, “a”, “b”, “c”]


Q6. What is an algorithm?

  • A function that finds matches to a pattern
  • A set of guidelines to keep code consistent
  • A function that returns information
  • A set of rules to solve a problem

Answer: A set of rules to solve a problem


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q7. What does the \w symbol match to in a regular expression?

  • Any letter
  • Any character and symbol
  • Any alphanumeric character
  • Any number
See also  Automate Cybersecurity Tasks with Python | Week 2

Answer: Any alphanumeric character


Q8. You have imported the re module into Python with the code import re. Which code searches the device_ids string variable for a pattern of “r15\w+”?

  • re.findall(device_ids, “r15\w+”)
  • findall(“r15\w+”, device_ids)
  • re.findall(“r15\w+”, device_ids)
  • findall(device_ids, “r15\w+”)

Answer: re.findall(“r15\w+”, device_ids)


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q9. Which method adds input to the end of a list?

  • .append()
  • .lower()
  • .insert()
  • .index()

Answer: .append()


Q10. What is the output of the following code?
print(len(“125”))

  • 3
  • 5
  • 8
  • 10

Answer: 3


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q11. Which line of code returns a copy of the string “bmoreno” as “BMORENO”?

  • print(“bmoreno”.upper())
  • print(upper.”bmoreno”())
  • print(upper(“bmoreno”))
  • print(“bmoreno”(upper))

Answer: print(“bmoreno”.upper())


Q12. What is the index of the character “c” in the string “encryption”?

  • 1
  • 2
  • 3
  • 4

Answer: 2


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q13. What is the output of the following code?
username_list = [“elarson”, “bmoreno”, “tshah”]
device_id_list = [“us2c0R5”, “2R78TBR”, “bt3MIEz”]
print(username_list + device_id_list)

  • [“elarson”, “us2c0R5”, “bmoreno”, “2R78TBR”, “tshah”, “bt3MIEz”]
  • [“us2c0R5”, “2R78TBR”, “bt3MIEz”, “elarson”, “bmoreno”, “tshah”]
  • An error message
  • [“elarson”, “bmoreno”, “tshah”, “us2c0R5”, “2R78TBR”, “bt3MIEz”]

Answer: [“elarson”, “bmoreno”, “tshah”, “us2c0R5”, “2R78TBR”, “bt3MIEz”]


Q14. A variable named my_list contains the list [1,2,3,4]. Which line of code removes the last element in the list?

  • remove (my_list, 3)
  • remove(my_list, 4)
  • my_list.remove(3)
  • my_list.remove(4)

Answer: my_list.remove(4)


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q15. What module do you need to import to use regular expressions in Python?

  • os
  • time
  • re
  • csv

Answer: re


Q16. What is the result when .upper() is applied to a string?

  • The character that appears most frequently in the string is extracted from it and returned.
  • The value of the string is reassigned to the value of the string in the line preceding it.
  • The value of the string is reassigned to contain all uppercase letters.
  • A copy of the string is returned with all uppercase letters.

Answer: A copy of the string is returned with all uppercase letters.


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q17. What is the output of the following code?
approved_users = [“bmoreno”, “elarson”, “tshah”, “eraab”]
print(approved_users[1])

  • “elarson”
  • [“bmoreno”, “elarson”, “tshah”, “eraab”, 1]
  • “bmoreno”
  • [1, “bmoreno”, “elarson”, “tshah”, “eraab”]

Answer: “elarson”


Q18. You imported a Python module, what do you now have access to in Python?

  • A manual that informs the writing, formatting, and design of documents
  • A function that exists within Python and can be called directly
  • A list of comments that you have included in previous code
  • Additional functions, variables, classes, and other kinds of runnable code

Answer: Additional functions, variables, classes, and other kinds of runnable code

See also  Automate Cybersecurity Tasks with Python | Week 4

These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q19. Fill in the blank: A(n) _____ is a set of rules to solve a problem.

  • append
  • algorithm
  • regular expression
  • index

Answer: algorithm


Q20. Which of the following strings match with the regular expression pattern of “\w”? Select all that apply.

  • “W”
  • “security”
  • “2”
  • “1B”

Answer: “W”
“2”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q21. What does the re.findall() function return?

  • All possible regular expressions that match to a given string
  • A list of all matches to a regular expression in a given string
  • The first match to a regular expression in a given string
  • All occurrences of the pattern “re” in a given string

Answer: A list of all matches to a regular expression in a given string


Q22. What does the code username_list.append(“bmoreno”) method do?

  • Returns all matches to the pattern “bmoreno” in the username_list list
  • Inserts “bmoreno” at the beginning of the username_list list
  • Adds “bmoreno” to the end of the username_list list
  • Updates all instances of “bmoreno” in the username_list list to uppercase letters

Answer: Adds “bmoreno” to the end of the username_list list


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q23. Which line of code returns the number of characters in the string assigned to the username variable?

  • print(len(username))
  • print(username.len())
  • print(str(username))
  • print(username.str())

Answer: print(len(username))


Q24. Which code joins a list of new_users to a list of approved_users and assigns the value to a third variable named users?

  • users(new_users[1], approved_users[2])
  • users = insert(new_users, approved_users)
  • users = new_users + approved_users
  • users(new_users, approved_users)

Answer: users = new_users + approved_users


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q25. Fill in the blank: Determining that you need to use string slicing and a for loop to extract information from items in a list is part of creating a(n) _____.

  • index
  • regular expression
  • append
  • algorithm

Answer: algorithm


Q26. In the string “network”, which character has an index of 1?

  • “e”
  • “n”
  • “k”
  • “t”

Answer: “e”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


Q27. You need to take a slice from a network ID. Specifically, you must extract the characters with indices of 6 through 10. Complete the Python code to take this slice and display it. (If you want to undo your changes to the code, you can click the Reset button.)

Answer:
network_id = "l693m585n528"
###YOUR CODE HERE###
print(network_id[6:11])

What string does the code output?

  • “m585n”
  • “585n5”
  • “5n528”
  • “85n52”

Answer: “85n52”


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz


More Weeks of this course: Click Here

More Coursera Courses: http://progiez.com/coursera


These are Automate Cybersecurity Tasks with Python Answers Week 3 Coursera Quiz