Automate Cybersecurity Tasks with Python | Week 1

Week 1 – Introduction to Python

Course Name: Automate Cybersecurity Tasks with Python

Course Link: Automate Cybersecurity Tasks with Python

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


Test your knowledge: Introduction to Python programming in cybersecurity

Q1. What tasks would a security analyst most likely automate with Python? Select three answers.

  • Managing an access control list
  • Sorting through a log file
  • Analyzing network traffic
  • Addressing an unusual cybersecurity concern

Answer: Managing an access control list
Sorting through a log file
Analyzing network traffic


Q2. What are some benefits of using Python in security? Select all that apply.

  • Python reduces manual effort.
  • Python helps automate short, simple tasks.
  • Python is the only language that creates a specific set of instructions to execute tasks.
  • Python can combine separate tasks into one workstream.

Answer: Python reduces manual effort.
Python helps automate short, simple tasks.
Python can combine separate tasks into one workstream.


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


Q3. Which of the following code blocks contains a valid Python comment?

  • # This prints a “Try again” message
    print(“Try again”)
  • : This prints a “Try again” message
    print(“Try again”)
  • This prints a “Try again” message
    print(“Try again”)
  • comment: This prints a “Try again” message
    print(“Try again”)

Answer: # This prints a “Try again” message
print(“Try again”)


Q4. Which line of code outputs the string “invalid username” to the screen?

  • print(“invalid username”)
  • print(#invalid username#)
  • # print(“invalid username”)
  • print(invalid username)

Answer: print(“invalid username”)


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


Test your knowledge: Core Python components

Q1. Which of the following data items are float data? Select all that apply.

  • -2.11
  • “5.2”
  • 8
  • 15.0

Answer: -2.11
15.0


Q2. What code displays the data type of the variable username?

  • username = [“elarson”, “bmoreno”, “tshah”]
    type(username) = data_type
    print(data_type)
  • username = [“elarson”, “bmoreno”, “tshah”]
    data_type = username
    print(data_type)
  • username = [“elarson”, “bmoreno”, “tshah”]
    data_type = type()
    print(data_type)
  • username = [“elarson”, “bmoreno”, “tshah”]
    data_type = type(username)
    print(data_type)

Answer: username = [“elarson”, “bmoreno”, “tshah”]
data_type = type(username)
print(data_type)


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


Q3. In the following code, what is the data type of login_success?
login_success = [“success”, “success”, “fail”, “success”]

  • Integer
  • String
  • List
  • Boolean

Answer: List


Q4. What is the output of the following code?
failed_attempts = 3
failed_attempts = 4
print(failed_attempts)

  • 3
  • 4
  • 7
  • 3, 4

Answer: 4


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


Test your knowledge: Conditional and iterative statements

Q1. What will the following code display?
ip_address = “192.168.183.51”
if ip_address == “192.168.183.51”:
print(“You’re logged in.”)
else:
print(“Login failed, try again.”)

  • Both “You’re logged in.” and “Login failed, try again.”
  • Nothing
  • “You’re logged in.”
  • “Login failed, try again.”

Answer: “You’re logged in.”


Q2. Which conditional statement prints the message “account locked” when the value of failed_logins is 3 or higher?

  • if failed_login_count != 3:
    print(“account locked”)
  • if failed_logins >= 3:
    print(“account locked”)
  • if failed_login_count > 3:
    print(“account locked”)
  • if failed_login_count == 3:
    print(“account locked”)

Answer: if failed_logins >= 3:
print(“account locked”)


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


Q3. Which code prints all numbers from 3 to 7?

  • for i in range(3, 4, 5, 6, 7):
    print(i)
  • for i in range(8):
    print(i)
  • for i in range(3, 8):
    print(i)
  • for i in range(3, 7):
    print(i)

Answer: for i in range(3, 8):
print(i)


Q4. How many times does the following code print the “security alert” message?
count = 0
while count < 10:
print(“security alert”)
count = count + 1

  • 5
  • 10
  • 0
  • 9
See also  Automate Cybersecurity Tasks with Python | Week 3

Answer: 10


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


Module 1 challenge

Q1. Fill in the blank: Automation is _____.

  • the use of human and manual effort to reduce technological power consumption
  • the use of technology to reduce human and manual effort to perform common and repetitive tasks
  • the combination of technology and manual effort to complete a task
  • the replacement of existing technology

Answer: the use of technology to reduce human and manual effort to perform common and repetitive tasks


Q2. What is wrong with the following code?
for username in failed_login:
print(username)

  • The first line should be split in two, and in failed_login: should be indented on the new line.
  • Both lines are not indented.
  • The line with for username in failed_login: is not indented.
  • The line with print(username) is not indented.

Answer: The line with print(username) is not indented.


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


Q3. What data type requires quotation marks (” “)?

  • Boolean
  • String
  • Float
  • Integer

Answer: String


Q4. Which line of Python code would create a Boolean value of True?

  • print(“True”)
  • print([“Boolean”])
  • print(25<24)
  • print(10<100)

Answer: print(10<100)


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


Q5. Which line of code assigns the string “dtanaka” to a variable called username?

  • username = “dtanaka”
  • “dtanaka” = username
  •  username(“dtanaka”)
  • username = dtanaka

Answer: username = “dtanaka”


Q6. What will this code do when you run it?
var2 = [“a”,”b”,”c”]
var2_type = type(var2)
print(var2_type)

  • Indicate that var2 contains list data
  • Change the data type of var2
  • Output the characters “a”, “b”, and “c” to the screen
  • Print the string “var2_type” to the screen

Answer: Indicate that var2 contains list data


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


Q7. You are checking whether the string stored in a device_id variable matches to the correct device ID, the string “15hgu3769”. When it matches, you want to print, “Login successful!”. Which conditional statement has the correct syntax needed to do this?

  • if device_id == “15hgu3769”:
    print(“Login successful!”)
  • if “device_id” = “15hgu3769”
    print(“Login successful!”)
  • if “device_id == 15hgu3769”
    print(“Login successful!”)
  • if device_id != “15hgu3769”
    print(“Login successful!”)

Answer: if device_id == “15hgu3769”:
print(“Login successful!”)


Q8. Fill in the blank: An else statement _____.

  • is required after every if statement
  • executes when the condition in the if statement preceding it evaluates to False
  • executes when the condition in the if statement preceding it evaluates to True
  • contains its own unique condition

Answer: executes when the condition in the if statement preceding it evaluates to False


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


Q9. What will this iterative statement do?
for i in [0, 5]:
print(i)

  • Output the integer 0
  • Output the integers 0, 1, 2, 3, and 4
  • Output the integers 0 and 5
  • Output the integers 0, 1, 2, 3, 4, and 5

Answer: Output the integers 0 and 5


Q10. If you want to run a loop that repeats if a count variable is less than 50, what code should your loop header contain?

  • while count < 50:
  • while count == 50:
  • print(50)
  • count = count + 50

Answer: while count < 50:


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


Q11. Fill in the blank: If you use Python code to reduce the manual effort needed to manage an access control list, this is an example of _____.

  • debugging
  • reassignment
  • automation
  • data analysis
See also  Automate Cybersecurity Tasks with Python | Week 3

Answer: automation


Q12. The purpose of the following code is to print an “Attempting connection” message while the value of the count variable is less than 10. The value of count should increase by 1 with each iteration of the loop. What is wrong with the code? Select all that apply.
count = 1
while count < 10:
print(“Attempting connection”)
count = count + 1

  • The line with print(“Attempting connection”) is not indented.
  • The line with while count < 10: is not indented.
  • The line with count = count + 1 is not indented.
  • The line with count = 1 is not indented

Answer: The line with print(“Attempting connection”) is not indented
The line with count = count + 1 is not indented.


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


Q13. Fill in the blank: String data _____.

  • must be placed in parentheses
  • must be placed in brackets
  • must be placed in quotation marks
  • must include a decimal point

Answer: must be placed in quotation marks


Q14. Which data type always has a value of either True or False?

  • Boolean
  • Float
  • List
  • String

Answer: Boolean


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


Q15. How do you assign the string value “rtp3426” to a variable called device_id?

  • device_id = “rtp3426”
  • device_id = rtp3426
  • device_id(rtp3426)
  • device_id(“rtp3426”)

Answer: device_id = “rtp3426”


Q16. Fill in the blank: If you ran the following code, the output would _______.
var1 = 9.5
var1_type = type(var1)
print(var1_type)

  • indicate that var1 contains float data
  • output 9.5 to the screen
  • reassign var1 as string data
  • reassign var1 as float data

Answer:: indicate that var1 contains float data


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


Q17. You wrote the following code:
if attempts >= 5:
print(“locked”)
else:
print(“try again”)
If the value in the attempts variable is 3, what will Python do?

  • First output the message “try again” and then output the message “locked”
  • Output the message “locked”
  • Output the message “try again”
  • First output the message “locked” and then output the message “try again”

Answer: Output the message “try again”


Q18. What iterative statement should you use if you want to print the numbers 1, 2, and 3?

  • for i in [1,3]:
    print(i)
  • for i in range(1,3):
    print(i)
  • for i in range(0,3):
    print(i)
  • for i in [1, 2, 3]:
    print(i)

Answer: for i in [1, 2, 3]:
print(i)


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


Q19. How many times will the following code print the “warning” message?
count = 1
while count < 5:
print(“warning”)
count = count + 1

  • 5
  • 1
  • 4
  • 0

Answer: 4


Q20. You are implementing security measures on a server. If a user has more than 3 failed login attempts, the program should print “locked out”. The number of failed login attempts is stored in a variable called failed_attempts. Which conditional statement has the correct syntax needed to do this?

  • if failed_attempts >= 3
    print(“locked out”)
  • if failed_attempts <= 3:
    print(“locked out”)
  • if failed_attempts > 3:
    print(“locked out”)
  • if failed_attempts < 3
    print(“locked out”)

Answer: if failed_attempts > 3:
print(“locked out”)


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


Q21. You have written the following code:
if operating_system == “OS 3”:
print(“Updates needed”)
You want to add to it so that it will print a “No updates needed” message whenever the value of operating_system is not “OS 3”. Which lines of code have the correct syntax to do this?

  • else:
    print(“No updates needed”)
  • else
    print(“No updates needed”)
  • elif operating_system == “OS 3”:
    print(“No updates needed”)
  • else operating_system != “OS 3”:
    print(“No updates needed”)
See also  Automate Cybersecurity Tasks with Python | Week 4

Answer: else:
print(“No updates needed”)


Q22. In a cybersecurity setting, which of these tasks would it be common to apply Python to? Select all that apply.

  • Automating several tasks from a playbook into one workstream
  • Manually checking individual timestamps in a log
  • Automating how a log is read when responding to an incident
  • Reducing the effort needed to manage an access control list

Answer: Automating several tasks from a playbook into one workstream
Automating how a log is read when responding to an incident
Reducing the effort needed to manage an access control list


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


Q23. What is the syntax problem in the following code?
if username == “aestrada”:
print(“username found”)

  • The first line should be indented one space, and the second line should be indented two spaces.
  • The line with print(“username found”) is not indented.
  • The line with if username == “aestrada”: is not indented.
  • Both lines are not indented.

Answer: The line with if username == “aestrada”: is not indented.


Q24. What are the variables in the following code? Select all that apply.
username = “kcarter”
attempts = 5
print(username)
print(attempts)
print(“locked”)

  • “kcarter”
  • attempts
  • username
  • “locked”

Answer: attempts
username


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


Q25. You want to check the string stored in an update_status variable. When it contains a value of “incomplete”, you want to print a “schedule update” message. Right now, this conditional statement is not correct. What are the problems with this conditional statement? Select all that apply.
if update_status != “incomplete”
print(“schedule update”)

  • A colon (:) is missing at the end of the conditional header.
  • The operator should not be !=. It should be ==.
  • There should be quotation marks around the variable update_status.
  • The line with print(“schedule update”) should not be indented.

Answer: A colon (:) is missing at the end of the conditional header.
The operator should not be !=. It should be ==.


Q26. You want to print all even numbers between 0 and 10 (in other words, 0, 2, 4, 6, 8, and 10). What should your next line of code be?
count = 0
while count <= 10:
print(count)

  • count = count + 1
  • if count < 10:
  • count = 1
  • count = count + 2

Answer: count = count + 2


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


Q27. Which of these are string data? Select all that apply.

  • 100
  • “100”
  • [100, 200, 300]
  • “user1”

Answer: “100”
“user1”


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


Q28. What are possible values for the Boolean data type? Select all that apply.

  • >
  • False
  • !=
  • True

Answer: False
True


These are Automate Cybersecurity Tasks with Python Answers Week 1 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 1 Coursera Quiz