Lecture "Programming languages", exercise 2
essepuntato opened this issue Β· 20 comments
What is the boolean value of "spam" not in "spa span sparql" and not ("egg" > "span")
?
True.
"spam" not in "spa span sparql" = True
not ("egg" > "span") = not (False) = True
True and True = True
I think the solution is True
. Indeed, βspamβ in "spa span sparql" = F
and βeggβ > βspanβ = F
. As a consequence, the question can be interpreted as following:
"spam" not in "spa span sparql" and not ("egg" > "span")
not False and not False
True and True = True
The value is True
:
- "spam" not in "spa span sparql" =
True
- not ("egg" > "span") =
True
So,
"spam" not in "spa span sparql" and not ("egg" > "span")
=
True and True
=
True
"spam" not in "spa span sparql" and not ("egg" > "span")=
True and not(False)=
True and True=
True
The answer is: True
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql"
=True
not ("egg" > "span")
=not (False)
=True
True and True
=True
The value is True
, because spam not in "spa span sparql"
= True
and not ("egg" > "span")
= not False
Then not False
= True
, so True and True
= True
.
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql" and not (False)
"spam" not in "spa span sparql" and True
True and True
True
"spam" not in "spa span sparql" = True
"not("egg">"span") = not(False) = True
Note, python uses unicode to compare strings and compares them character by character. Here, the unicode value of 'e from egg' is smaller than 's from span' as e comes before in the alphabets and in the unicode. It gives us the the result false which gets converted to true with the help of not operation.
now the final equation looks like : True and True = True.
Thus the final output will be True or 1
1)not 2)and 3)or
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql" and (not ("egg" > "span"))
("spam" not in "spa span sparql") and (not ("egg" > "span"))
(true) and (not (false))
(true) and (not false))
true and true = true
the Boolean value is True
"spam" not in "spa span sparql" and not False = True
The boolean value of "spam" not in "spa span sparql" and not ("egg" > "span") is True.
The boolean value is True
"spam" not in "spa span sparql" and not ("egg" > "span")
= True and not False
= True and True
= True
"spam" NOT IN "spa span sparql" and NOT ("egg" > "span")
TRUE and NOT (FALSE) #because ""egg is lexicographically before "span", so should be βeggβ < βspanβ
TRUE and TRUE
TRUE
{"spam" not in "spa span sparql"} and {not ("egg" > "span")}
We have {True} and {not(False)} = {True} and {True} = {TRUE}
"spam" not in "spa span sparql" and not ("egg" > "span")
= True and not False = True and True = True
"Spam" not in "spa span sparql" and not ("egg" > "span" ) ->
True and not False ->
True and True -> True
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql" and not (False)
True and True
True
"spam" not in "spa span sparqi" ββ> True
βegg">"span" ββ> False
not False ββ> True
True and True ββ> True
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql" = True
not ("egg" > "span") = Not False
= True
True and True
= True