Letβs now expand the use of our conditionals to account for other types like: π€
, or π’
, or π―
! But thereβs a question of, βhow do we convert the types π€
,π’
, and π―
to π
values?β Well, thatβs where the π
comes in!
π
compares two values, one on its left side and one on its right side, to see if they have the same value. The entire piece of code is an expression, we can think of expressions as code that evaluates to a value. In this case, the expression evaluates back to a π
or π
value.
Letβs see a few examples:
100 π 100 π Evaluates to: π 100 π 101 π Evaluates to: π 32.1 π 32 π Evaluates to: π 4.2 π 4.2 π Evaluates to: π π€Aπ€ π π€Aπ€ π Evaluates to: π π€Aπ€ π π€Bπ€ π Evaluates to: π π€Aπ€ π π€aπ€ π Evaluates to: π
Read through the examples and make sure you understand how the comparison works. Letβs also take a look at the π
usage in a conditional:
βͺοΈ π€cokeπ€ π π€pepsiπ€ π π π€They're the same thingπ€βοΈ π π π π π€They're NOT the sameπ€βοΈ π
In the example above, our condition is the expression π€cokeπ€ π π€pepsiπ€
. Since the strings are not the same, they're NOT the same
is printed to the terminal.
Instructions
Under the declared variables enteredPIN
and correctPIN
, add a βͺοΈ
statement that checks if enteredPIN
and correctPIN
are the same string using the π
operator.
Inside the π
π
block, add a πβοΈ
to print out π€Access grantedπ€
.
We should also add an else statement using π
. Inside this π
π
block, use πβοΈ
to print out π€Access deniedπ€
.