Until now your script printed the config for any VLAN number, even 5000.
A switch only accepts VLAN 1 to 4094, so the script must check first.To check, you use a comparison and Python answers True or False.

Figure 1 - One = Stores, Two == Compare
Python has six signs to compare values, called comparison operators:
vlan_id == 20 equal to vlan_id != 20 not equal to vlan_id < 20 lower than vlan_id > 20 greater than vlan_id <= 4094 lower than or equal to vlan_id >= 1 greater than or equal toTo see the answer of a comparison, you print it like this:
vlan_id = 5000 print(vlan_id <= 4094) # Output: FalseIn the lab, print a comparison that checks if
vlan_idis greater than or equal to 1 to get the flag.Answer the question below
Enter the flag you obtained.
To run some lines only when a test is True, you use
if.
Here the variablestatusholds the state of a port:
Figure 2 - Inside and Outside the if
The
ifline ends with the sign:and the line under it starts with four spaces.In the lab, make the script print
VLAN too highonly whenvlan_idis greater than 4094 to get the flag.Answer the question below
Enter the flag you obtained.
To run other lines when the test is False, you add
else.
Python runs the lines underifor underelse, never both:
Figure 3 - if or else, Never Both
In the lab, the script prints nothing because the port is up.
Add anelsethat printsThe port is in useto get the flag.Answer the question below
Enter the flag you obtained.
elifmeans "else if" and adds another test.
Python checks the tests from top to bottom and stops at the first one that is True:
Figure 4 - Python Stops at the First True
In the lab, the script does not know the status "down".
Add anelifthat printsThe port is freewhenstatusis "down" to get the flag.Answer the question below
Enter the flag you obtained.
The test
vlan_id <= 4094also accepts VLAN 0.
But VLAN 0 does not exist, so a good VLAN number must pass two tests.When you join two tests with
and, the answer is True only when both tests are True:
Figure 5 - and Keeps the VLAN Between 1 and 4094
When you join them with
or, only one test needs to be True:if status == "up" or status == "down": print("The status is known")In the lab, the script says that VLAN 0 is valid.
Add a second test withandto make it printVLAN is not validand get the flag.Answer the question below
Enter the flag you obtained.