All Coursera Quiz Answers

Test your knowledge: Work with files in Python Quiz Answer

In this article i am gone to share Coursera Course: Automate Cybersecurity Tasks with Python Week 4 Practice Quiz | Test your knowledge: Work with files in Python Quiz Answer with you..

Enroll Link:  Automate Cybersecurity Tasks with Python

About this Course: In this course, you will be introduced to the Python programming language and apply it in a cybersecurity setting to automate tasks. You’ll start by focusing on foundational Python programming concepts, including data types, variables, conditional statements, and iterative statements. You’ll also learn to work with Python effectively by developing functions, using libraries and modules, and making your code readable. In addition, you’ll work with string and list data, and learn how to import, parse and debug files. Google employees who currently work in cybersecurity will guide you through videos, provide hands-on activities and examples that simulate common cybersecurity tasks, and help you build your skills to prepare for jobs.


Also visit:  Test your knowledge: Python and automation Quiz Answer


 

Test your knowledge: Work with files in Python Quiz Answer

Question 1)
You want to open the file “logs.txt” and store it in the file variable for the purpose of reading it. You also want to ensure all resources are released and the file is closed after you read it. What is the correct line of code to do this?

  • file = open(“logs.txt”, “r”):
  • with open(“logs.txt”, “r”) as file:
  • with open(“r”, “logs.txt”) as file:
  • with file.open(“logs.txt”, “r”):

Question 2)
After you’ve opened a log file as login_file, which line of code can you use to read the file and store it in a variable called login_attempts?

  • login_attempts = read(login_file)
  • login_file.read() as login_attempts
  • login_attempts = login_file.reader()
  • login_attempts = login_file.read()

Question 3)
You just read a log file into a variable called file. The file variable contains a string of multiple IP addresses that are each separated by a whitespace. Which line of code separates each individual IP address and stores it as a list in a variable called ip_addresses?

  • ip_addresses = split(file)
  • ip_addresses = file.split()
  • ip_addresses.split(file)
  • split(file, ip_addresses)

Question 4)
You need to check for unusual login activity. Specifically, you need to check a list of login timestamps to determine if any of the login times occurred at unusual hours. If you want to automate this through Python, what would be part of your code? Select two answers.

  • A for loop that iterates through the list of timestamps
  • An if statement that checks if the login timestamp occurred at unusual hours
  • A counter variable that keeps track of the number of failed login attempts
  • An if statement that checks if a specific user has multiple login timestamps during unusual hours