automate cybersecurity tasks with python coursera weekly challenge 1 answers

Test your knowledge: Introduction to Python programming in cybersecurity

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

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

2. 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.

3. 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”)

4. Which line of code outputs the string "invalid username" to the screen?

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

Test your knowledge: Core Python components

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

  • -2.11
  • 8
  • 15.0
  • “5.2”

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

  • username = [“elarson”, “bmoreno”, “tshah”]

    data_type = type()

    print(data_type)

  • username = [“elarson”, “bmoreno”, “tshah”]

    data_type = username

    print(data_type)

  • username = [“elarson”, “bmoreno”, “tshah”]

    data_type = type(username)

    print(data_type)

  • username = [“elarson”, “bmoreno”, “tshah”]

    type(username) = data_type

    print(data_type)

7. In the following code, what is the data type of login_success?

login_success = ["success", "success", "fail", "success"]

  • Integer
  • String
  • List
  • Boolean

8. What is the output of the following code?

failed_attempts = 3

failed_attempts = 4

print(failed_attempts)

  • 3
  • 7
  • 4
  • 3, 4

Test your knowledge: Conditional and iterative statements

9. 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.")

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

10. 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_login_count != 3:

        print(“account locked”)

  • if failed_logins >= 3:

        print(“account locked”)

  • if failed_login_count == 3:

        print(“account locked”)

11. 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, 7):

        print(i)

  • for i in range(3, 8):

        print(i)

12. How many times does the following code print the "security alert" message?

count = 0

while count < 10:

print("security alert")

count = count + 1

  • 5
  • 0
  • 9
  • 10

Weekly challenge 1

13. 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

14. What is wrong with the following code?

for username in failed_login:

print(username)

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

15. What data type requires quotation marks (" ")?

  • Boolean
  • String
  • Float
  • Integer

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

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

17. Which line of code assigns the string "dtanaka" to a variable called username?

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

18. 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

19. 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!”)

20. 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

21. 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

22. 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

23. 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

24. 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

25. 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

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

  • Boolean
  • Float
  • List
  • String

27. 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”)

28. 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

29. 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”

30. 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)

31. 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

32. 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”)

33. 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”)

34. 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

35. 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.

36. 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”

37. 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.

38. 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

Leave a Reply