COURSE 7 /MODULE ONE. Activity: Assign Python variables

Ace your homework & exams now with Quizwiz!

Scenario

You are a security analyst who is responsible for writing code that will automate analysis of login attempts made to a specific device. As the first step, you'll need to create variables to keep track of information relevant to the login process. This information includes the device ID, list of approved usernames, maximum login attempts allowed per user, current login attempts made by a user, and login status. Throughout this lab, you'll assign these variables and check the data types of the variables.

Task 7 In this task, define a variable called login_attempts that represents the current number of login attempts made by a user. Store the value 2 in this variable. Then, store its data type in a variable called login_attempts_type. Display login_attempts_type to observe the output. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `login_attempts` to the value 2 ### YOUR CODE HERE ### # Assign `login_attempts_type` to the data type of `login_attempts` ### YOUR CODE HERE ### # Display `login_attempts_type` ### YOUR CODE HERE ### # Assign `login_attempts` to the value 2 login_attempts_type = 2 ### YOUR CODE HERE ### # Assign `login_attempts_type` to the data type of `login_attempts` login_attempts_type = type(login_attempts_type) ### YOUR CODE HERE ### # Display `login_attempts_type `print(login_attempts_type) ### YOUR CODE HERE ### result <class 'int'>

Task 10 Finally, you can also assign a Boolean value of True or False to a variable. In this task, you'll create a variable called login_status, which is a Boolean that represents whether a user is logged in. Assign False to this variable and store its data type in a variable called login_status_type and display it. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `login_status` to the Boolean value False login_status = ### YOUR CODE HERE ### # Assign `login_status_type` to the data type of `login_status` login_status_type = type(login_status) # Display `login_status_type` print(login_status_type) # Assign `login_status` to the Boolean value False login_status = False login_status = ### YOUR CODE HERE ### # Assign `login_status_type` to the data type of `login_status` login_status_type = type(login_status) # Display `login_status_type` print(login_status_type)

Task 6 In this task, define a variable called max_logins that represents the maximum number of login attempts allowed per user. Store the value 3 in this variable. Then, store its data type in another variable called max_logins_type. Display max_logins_type to examine the output. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `max_logins` to the value 3 ### YOUR CODE HERE ### # Assign `max_logins_type` to the data type of `max_logins` ### YOUR CODE HERE ### = type(max_logins) # Display `max_logins_type` ### YOUR CODE HERE ###(max_logins_type) # Assign `max_logins` to the value 3 max_logins_type = 3 ### YOUR CODE HERE ### # Assign `max_logins_type` to the data type of `max_logins` max_logins_type = type(max_logins_type) ### YOUR CODE HERE ### = type(max_logins) # Display `max_logins_type` ### YOUR CODE HERE ###(max_logins_type) print(max_logins_type) result <class 'int'>

Task 9 This code continues to check for the Boolean value of whether max_logins is less than or equal to login_attempts. In this task, reassign other values to login_attempts. For example, you might choose a value that is higher than the maximum number of attempts allowed. Observe how the output changes. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `max_logins` to the value 3 max_logins = 3 # Assign `login_attempts` to a specific value login_attempts = ### YOUR CODE HERE ### # Determine whether the current number of login attempts a user has made is less than or equal to the maximum number of login attempts allowed, # and display the resulting Boolean value print(login_attempts <= max_logins) # Assign `max_logins` to the value 3 max_logins = 3 # Assign `login_attempts` to a specific value login_attempts = ### YOUR CODE HERE ### login_attempts = 4 # Determine whether the current number of login attempts a user has made is less than or equal to the maximum number of login attempts allowed, # and display the resulting Boolean value print(login_attempts <= max_logins)

Task 8 In this task, you'll determine the Boolean value that represents whether the current number of login attempts a user has made is less than or equal to the maximum number of login attempts allowed. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `max_logins` to the value 3 max_logins = 3 # Assign `login_attempts` to the value 2 login_attempts = 2 # Determine whether the current number of login attempts a user has made is less than or equal to the maximum number of login attempts allowed, # and display the resulting Boolean value print(### YOUR CODE HERE ### <= ### YOUR CODE HERE ###) # Assign `max_logins` to the value 3 max_logins = 3 # Assign `login_attempts` to the value 2 login_attempts = 2 # Determine whether the current number of login attempts a user has made is less than or equal to the maximum number of login attempts allowed, # and display the resulting Boolean value print(3<=2) print(### YOUR CODE HERE ### <= ### YOUR CODE HERE ###)

Task 3 As you continue your work, you're provided a list of usernames of users who are allowed to access the device. The usernames with this access are "madebowa", "jnguyen", "tbecker", "nhersh", and "redwards". In this task, create a variable called username_list. Assign a list with the approved usernames to this variable. Then, display the value of the username_list variable. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `username_list` to the list of usernames who are allowed to access the device username_list = ### YOUR CODE HERE ### # Display `username_list` print(### YOUR CODE HERE ###) # Assign `username_list` to the list of usernames who are allowed to access the device username_list = {"madebowa", "jnguyen", "tbecker", "nhersh", "redwards"} # Display `username_list` print(username_list) print(### YOUR CODE HERE ###)

Task 4 In this task, find the data type of the username_list. Store the type in a variable called username_list_type. Then, display username_list_type to examine the output. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `username_list` to the list of usernames who are allowed to access the device username_list = ["madebowa", "jnguyen", "tbecker", "nhersh", "redwards"] # Assign `username_list_type` to the data type of `username_list` username_list_type = ### YOUR CODE HERE ### # Display `username_list_type` ### YOUR CODE HERE ### # Assign `username_list_type` to the data type of `username_list` username_list_type = ### YOUR CODE HERE ### username_list_type = type(["madebowa", "jnguyen", "tbecker", "nhersh", "redwards"]) # Display `username_list_type` ### YOUR CODE HERE ### print(username_list_type)

Task 5 Now, imagine that you've been informed that the previous list is not up-to-date and that there is another employee that now has access to the device. You're given the updated list of usernames with access, including the new employee, as follows: "madebowa", "jnguyen", "tbecker", "nhersh", "redwards", and "lpope". In this task, reassign the variable username_list to the new list. Run the code to display the list before and after it's been updated to observe the difference. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign `username_list` to the list of usernames who are allowed to access the device username_list = ["madebowa", "jnguyen", "tbecker", "nhersh", "redwards"] # Display `username_list` print(username_list) # Assign `username_list` to the updated list of usernames who are allowed to access the device ### YOUR CODE HERE ### = ["madebowa", "jnguyen", "tbecker", "nhersh", "redwards", "lpope"] # Display `username_list` print(username_list) # Assign `username_list` to the updated list of usernames who are allowed to access the device username_list = ["madebowa", "jnguyen", "tbecker", "nhersh", "redwards", "lpope"] ### YOUR CODE HERE ### = ["madebowa", "jnguyen", "tbecker", "nhersh", "redwards", "lpope"] # Display `username_list` print(username_list) result ['madebowa', 'jnguyen', 'tbecker', 'nhersh', 'redwards'] ['madebowa', 'jnguyen', 'tbecker', 'nhersh', 'redwards', 'lpope']

Task 2 Now that the variable device_id is defined, you can return its data type. In this task, use a Python function to find the data type of the variable device_id. Store the data type in another variable called device_id_type. Then, display device_id_type to examine the output. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign the `device_id` variable to the device ID that only specified users can access device_id = "72e08x0" # Assign `device_id_type` to the data type of `device_id` device_id_type = ### YOUR CODE HERE ### device_id_type = type(device_id) # Display `device_id_type` print(### YOUR CODE HERE ###) print(device_id_type) results. <class 'str'>

Task 1 In your work as an analyst, imagine there is a device only users specified on an allow list can access, and its device ID is "72e08x0". In the following code cell, assign this value to a variable named device_id. Then, display the contents of the variable and observe the output. Be sure to replace each ### YOUR CODE HERE ### with your own code before you run the following cell.

# Assign the `device_id` variable to the device ID that only specified users can access device_id = "72e08x0" # Display `device_id` print(device_id) shift enter to get your results 72e08x0

Lab instructions Start the lab From this page, click Open Lab. The notebook that contains your lab will open in a new browser tab. Complete all the tasks in this lab before moving on. The next course item will be an exemplar of a completed lab. You'll be able to compare the code and text responses in the exemplar to the ones that you enter in this lab.

End the lab When you have completed all the tasks and answered all the questions in the lab, you can close the browser tab containing the lab. (The changes you have made to the lab will be saved, and if you click Open Lab again, you can access your previous work in the lab.) Sometimes you need to refresh your Coursera page in order for your progress to be registered. If you refresh this page after you complete your lab, the green check mark should appear.

Lab features As you complete the lab, note the following features: Tasks: Step-by-step instructions in each task lead you through the lab. Questions: Reflection questions offer moments to pause and think about concepts and your output as you move through the lab.

Hints: Hidden hints provide optional suggestions you can use to complete your work.

Based on the different values you assigned to login_attempts, what did you observe about the output?

I chose 4 which made 3 not greater than 4. so it was false.]

Introduction

Variables help security analysts to keep track of a variety of security-related information. For example, analysts may need to create Python variables for the users who are allowed to log in, the number of login attempts that they're permitted, and the current number of attempts that a user has made. In this lab, you'll practice assigning values to variables and determining their data types.

What is the output? What does this mean?

[3 is not equal to 2 so it is False

Based on the output above, what do you observe about the data type of login_attempts?

[Data type <class 'int'>.

Question 3 Based on the output above, what do you observe about the contents of username_list?

[The data list was updated.]

Question 2 Based on the output above, what do you observe about the data type of username_list?

[the data type is list <class 'list'>]<class 'list'> its a

Question 4 Based on the output above, what do you observe about the data type of max_logins?

data type <class 'int'>

Question 8 Based on the output above, what do you observe about the data type of login_status?

data type is boolean.


Related study sets

Chapter 26: Concepts of Care for Patients with Noninfectious Upper Respiratory Problems

View Set

Chapter 16: Disorders of Brain Function Patho Prep U

View Set

Chapter 1 Review- Macroeconomics

View Set

APES test unit 4 (+ AP classroom questions)

View Set

GMU IT 343 Midterm Chpt 1-8 review quizzes

View Set

Chapter 21: Nursing management of labor and birth at risk

View Set

Complete Endocrine System: Glands, Hormones and Disorders

View Set

Human Development: Life Span (Broderick) #3

View Set