automate cybersecurity tasks with python coursera weekly challenge 2 answers

Test your knowledge: Introduction to functions

1. In Python, what is a function?

  • A section of code that contains a conditional
  • A section of code that exists directly in Python
  • A section of code that can be reused in a program
  • A section of code that contains an iterative statement

2. Which of the following keywords is essential when defining a function?

  • while
  • if
  • def
  • for

3. You want to define a function that performs a status check. Which of the following is a valid header for the function definition?

  • def status_check()
  • def status_check
  • def status_check:
  • def status_check():

4. You are responsible for defining a function alert() that prints out the statement "Security issue detected." Which of the following blocks of code represent the correct indentation for defining and then calling the function?

Test your knowledge: Arguments, parameters, and return statements

Test your knowledge: Arguments, parameters, and return statements

5. Fill in the blank: In the following code, the integers 5 and 12 are _____:

for i in range(5, 12):

print(i)

  • functions
  • parameters
  • return statements
  • arguments

6. What is the correct way to define the function addition() if it requires the two parameters num1 and num2?

  • def addition(num1 num2):
  • def addition(num1 and num2):
  • def addition(num1)(num2):
  • def addition(num1, num2):

7. Which of the following lines of code has correct syntax for printing the data type of the string "elarson"?

  • print(type, “elarson”)
  • print(type(“elarson”))
  • type(print(“elarson”))
  • print(“elarson”, type)

8. Which function definition includes the correct syntax for returning the value of the result variable from the doubles() function?

  • def doubles(num):

    result = num * 2

    return result

  • def doubles(num):

    result = num * 2

    result return

  • def doubles(num):

    result = num * 2

    return = result

  • def doubles(num):

    result = num * 2

    return “result”

Shuffle Q/A 1

Test your knowledge: Learn from the Python community

9. Which of these is not included in the Python Standard Library?

  • time
  • NumPy
  • re
  • csv

10. Which of the following resources provides recommendations about including comments in your code?

  • csv
  • re
  • Python Standard Library
  • PEP 8

Leave a Reply