Automate Cybersecurity Tasks with Python Weekly challenge 4 Quiz Answers
In this article i am gone to share Coursera Course: Automate Cybersecurity Tasks with Python Weekly challenge 4 Quiz Answers with you..
Enroll Link: Automate Cybersecurity Tasks with Python
Also visit: Automate Cybersecurity Tasks with Python Weekly challenge 3 Quiz Answers
Automate Cybersecurity Tasks with Python Weekly challenge 4 Quiz Answers
Question 1)
What are the three types of errors you will encounter while debugging?
- Logic errors, comment errors, and iterative errors
- Syntax errors, exceptions, and comment errors
- Syntax errors, logic errors, and exceptions
- Exceptions, logic errors, iterative errors
Question 2)
The purpose of the following code is to print the numbers from 0 to 9. Run this code, analyze its output, and then debug it. (If you want to undo your changes to the code, you can click the Reset button.)
count = 0while count < 10
print(“number”, count)
count = count + 1
count = 0
while count < 10
print(“number”, count)
count = count + 1
How can you fix the error?
- Add a missing colon (:)
- Remove the quotation marks around number
- Spell a variable correctly
- Change indentation
Question 3)
The purpose of the following code is to iterate through a list and print a warning message if it finds “user3” in the list. Run this code, analyze its output, and debug it. (If you want to undo your changes to the code, you can click the Reset button.)
list = [“user1”, “user2”, “user3”, “user4”]
for user in list: if user != “user3”:
print(“Warning: user3 should not access the system.”)
How can you fix the error?
- Change “user3” to “user2” in the conditional.
- Change “user3” to “user1” in the conditional.
- Change the indentation so that the line that prints the warning is not indented.
- Change the != operator to the == operator in the conditional.
Question 4)
You included username_list[10] in your code, but username_list only contains five elements. What type of error is this?
- Syntax error
- Name error
- Logic error
- Exception
Question 5)
When debugging code, what are effective ways to determine which sections of code are working properly? Select all that apply.
- Add comments in the code
- Add print statements
- Use a debugger
- Delete blank lines from the code
Question 6)
Which of these functions or arguments should you include in a with statement if you want Python to open a file called access.txt so that it can be read? Select three answers.
- “access.txt”
- open()
- “r”
- read()
Question 7)
You’ve read a log file into the variable file_text. The file_text variable contains a string of 50 usernames of employees at your company. In order to pass it into a function that checks the login count of each user, the string should be divided into a list of separate usernames. How do you convert this string into a list and store it in a variable usernames?
- usernames = split(usernames, file_text)
- file_text.split() as usernames
- usernames = file_text.split()
- usernames = usernames.split(file_text)
Question 8)
What is the process of converting data into a more readable format?
- Slicing
- Debugging
- Splitting
- Parsing
Question 9)
What does the following code do?
new_format = old_format.read()
Detects certain text patterns in old_format- Prints the contents of old_format
- Reads the old_format variable, which contains a file, and stores it as a string in new_format
Inserts the string stored in the new_format variable into the file stored in the old_format variable
Question 10)
You want to check if a device is running a particular operating system that needs updates. Devices that contain a substring of “i71” in their device ID are running this operating system. First, you want to read in a log file that contains the device ID for all devices and convert it into a string. You should then parse this string into a devices list. Then, you should separate all device IDs that contain the substring “i71” into a separate list called updates_list. If you want to automate this through Python, what would be part of your code? Select three answers.
- A for loop to iterate through all items in the devices list
- A counter variable to keep track of the number of devices containing the substring “i71”
- An if statement that checks if elements in devices contain the substring “i71”
- A split() function to split the string containing the information in the log file into a devices list
Question 11)
You want to check for unusual login activity. Specifically, you want to check if there were more than three failed login attempts in the last 10 minutes by the last user who logged in. If you want to automate this through Python, what would be part of your code? Select three answers.
- A for loop that iterates through the list of logins
- A line of code that reassigns a counter variable to 0 if there is a failed login attempt
- A counter variable that increments when a failed login is detected
- An if statement that checks if there were more than three failed login attempts
Question 12)
You did not assign a value to a variable before using it in a conditional. What type of error is this?
- Index out of bounds
- Logic error
- Syntax error
- Exception
Question 13)
Why might you use print statements when debugging code?
- To prevent errors from occurring
- To identify which sections of the code are working properly
- To create error messages
- To add missing syntax to the code
Question 14)
The logins variable is a string containing 20 device IDs. The device IDs are separated by spaces. In order to pass it into a function that checks the login count of each device, the string should be divided into a list of separate IDs. How do you convert this string into a list and store it in a device_ids variable?
- device_ids = logins.split()
- logins.split() as device_ids
- device_ids = device_ids.split(logins)
- device_ids = split(device_ids, logins)
Question 15)
Fill in the blank: If you use the .split() method to convert a string into a list so that it can be read more easily, this would be an example of _____.
- slicing
- parsing
- debugging
- dividing
Question 16)
After you’ve opened a log file as file, which line of code will help you read the file into a variable called text?
- text.read(file)
- text = file.read()
- text = read(file, “r”)
- text = read(file)
Question 17)
You want to check for unusual login activity. Specifically, you want to read a log file that contains information on each login attempt, including whether it failed or was successful. You should then parse the data into a logins list, and then you should separate all failed log entries into a separate failed_logins list. If you want to automate this through Python, what would be part of your code? Select three answers.
- An if statement to check if a login attempt failed
- A for loop to iterate through all items in the logins list
- A counter variable to keep track of the number of failed logins
- A split() function to split the login information into a list
Question 18)
If you know there is a logic error somewhere inside a function, how can you figure out the exact location?
- Place print statements in and around the function
- Move the function to another location
- Delete the function from the program
- Write comments in and around the function
Question 19)
If you want to read a file called “logs.txt”, which line of code allows you to open this file for purposes of reading it and store it in a variable called file?
- with open(“logs.txt”, file, “r”):
- with file.open(“logs.txt”, “r”):
- with open(“logs.txt”, “r”) as file:
- with open(“logs.txt”) as file:
Question 20)
The purpose of the following code is to print the characters in a device ID. Run this code, analyze its output, and then debug it. (If you want to undo your changes to the code, you can click the Reset button.)
device_id="p35rv47
for char in device_id:
print(char)
What is the error related to?
- A misspelled variable
- A missing double equals sign (==)
- A missing quotation mark (“)
- A missing colon (:)
Question 21)
What does the following code do?
with open("logs.txt", "r") as file:
- It copies a file called “logs.txt” into a new file “r”.
- It opens a file called “logs.txt” in write mode and stores it in a variable called file.
- It copies a file called “r” into a new file “logs.txt”.
- It opens a file called “logs.txt” in read mode and stores it in a variable called file.
Question 22)
What does the following code do?
read_text = text.read()
- Reads the string text and stores it the file read_text
- Splits the text variable, which contains a string, and stores it as a list in read_text
- Reads the text variable, which contains a file, and stores it as a string in read_text
- Replaces the contents of the file read_text with the contents of the file text
Question 23)
What is parsing?
- The process of reading data line by line
- The process of copying data to other files
- The process of writing data to a new file
- The process of converting data into a more readable format
Question 24)
What is the practice of identifying and fixing errors in code?
- Parsing
- Slicing
- Debugging
- Splitting
Question 25)
The purpose of this code is to print “user flagged” if the username is “jhill”, and otherwise to print “user okay”. Run this code, analyze its output, and debug it. (If you want to undo your changes to the code, you can click the Reset button.)
def check_user(name):
if name="jhill":
print("user flagged")
print("user okay")
check_user("jhill")
How can you fix this error?
- Call check_user() before the function definition.
- Remove indentation from the line that prints “user okay” so that it is not part of the conditional.
- Use the != operator instead of the == operator in the conditional header.
- Add an else statement before the line that prints “user okay”.
Question 26)
You did not define a function before calling it. What type of error is this?
- Index out of bounds
- Syntax error
- Logic error
- Exception
Question 27)
The purpose of the following code is to search a list. Run this code, analyze its output, and then debug it. (If you want to undo your changes to the code, you can click the Reset button.)
def search_list(username): for item in username: print(item) search_list(["elarson", "bmoreno", "tshah"])
What is the error related to?
- A missing colon (:)
- A misspelled variable
- A missing quotation mark (“)
- A missing comma (,)
Question 28)
You did not assign a value to a variable before using it in a conditional statement. What type of error is this?
- Syntax error
- Index out of bounds
- Logic error
- Exception
Question 29)
What does the following code do?
logins = "pwashing jhill tshah" usernames = logins.split()
- Splits a string variable called logins into single characters
- Removes the blank spaces that split the usernames in the variable logins and stores the string in the variable usernames
- Removes the last username in the logins variable and stores the string in the usernames variable
- Splits a string variable called logins into a list of strings and stores it in the variable usernames