Post

@clcoding Answer: 60 + 35 = 95 (each character on a separate line)
Solution: This question becomes easy once you understand `in` operator.
So let's start there.
The `in` operator is used to check membership.
Given 2 values x and y,
x in y
is either True or False
+
English

@clcoding x in y
is True if `x` is *contained in* `y`.
Else, False.
The exact meaning of *contained* depends on the types of operands.
In the case that `x` and `y` are str values,
x in y
returns True only if x is a substring of y.
What does that mean?
It means that
+
English

@clcoding that the string x occurs at least once in the string y.
Examples:
'na' in 'banana' : True
'zzz' in 'banana' : False
'bnn' in 'banana' : False
That's all we need to understand about `in` usage with strings
Now, `not in` simply inverts the condition.
+
English

@clcoding If the `in` result is True, `not in` result is False and vice versa
Now we are ready to solve the quiz
equation = '160 + 135 = 295'
creates a string named `equation`.
Note that these contents of string are treated as characters, not numbers.
Then the for-loop
+
English

@clcoding for symbol in equation:
...
loops over the characters in `equation`,
taking each character `symbol` in the iterations.
What happens in this loop?
if symbol not in '12':
...
Let's think for which values of symbol can this condition be False
+
English

@clcoding Any value that is a substring of "12" will lead to False condition.
So, those possibilities are:
"" (empty string)
'1'
'2'
"12"
But recall that `symbol` is always a single character from `equation`.
So, only the possiblities of '1' and '2' are relevant.
Thus,
+
English

@clcoding the condition is False for `symbol` value '1' and '2',
True for everything else.
Now let's see what happens if the condition is True.
print(symbol)
Putting together our analysis so far,
if `symbol` is not contained in "12" it is printed
In other words,
if `symbol` is either
+
English

@clcoding '1' or '2', it won't be printed.
Else, printed.
So, the code checks each character in `equation`, and prints it if it is neither '1' nor '2'.
That's a good simplification.
Let's now quickly look at `equation`, and crack it.
Characters other than '1' and '2' will be printed
+
English

@clcoding Equation being "160 + 135 = 295"
if we mentally remove '1's and '2's, what remains is
60 + 35 = 95
So these are the characters that get printed.
But note that each call to `print` prints on a separate line.
So it's NOT going to look like an equation
60 + 35 = 95
But
+
English

@clcoding rather each character on a separate line (including space)
6
0
+
3
5
=
9
5
And that's the answer!
English


