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

Automate Cybersecurity Tasks with Python | Weekly challenge 4 Quiz | 

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.

 

Leave a Comment