comp-think / 2018-2019

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2018/2019).
Other
30 stars 8 forks source link

Lecture "Programming languages", exercise 2 #10

Open essepuntato opened 5 years ago

essepuntato commented 5 years ago

What is the boolean value of "spam" not in "spa span sparql" and not ("egg" > "span")?

dersuchendee commented 5 years ago

“Spam” not in “spa span sparql” = T

Not (“egg”>”span”)= F

T and F = F

delfimpandiani commented 5 years ago

Mmmm.. I wonder if I got this wrong:

("spam" not in "spa span sparql") --> is "spam" not in "spa span sparql"? --> No = True

("egg" > "span") --> is "egg" bigger than "span" (is egg alphabetically bigger than span?) --> No = False

True and not (False)

True and True

True

mangiafrangette commented 5 years ago

"spam" not in "spa span sparql" = True and not ("egg" > "span") = True True and True = True

Note: I agree with @delfimpandiani: if "a string S1 is less than another string S2 if the former one precedes the latter one according to a pure alphabetic order" (Table 2, Programming languages lecture notes), I suppose that a string is greater than another string if the former follows the latter in alphabetical order, therefore "egg" > "span" = False because "egg" does not follow "span" in the alphabet.

lisasiurina commented 5 years ago

"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

simayguzel commented 5 years ago

"spam" not in "spa span sparql" = True ("egg" > "span") = False --- not False = True According to the Boolean value; True and True = True

federicabologna commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span") True and not (False) True and True True

EleonoraPeruch commented 5 years ago

ex 2 programming languages

Totaro1996 commented 5 years ago

"spam" not in "spa span sparql" and not ("egg">"span") T and not F T and t True

tceron commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span") True and not (False) True and True True

MattiaSpadoni commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span")

friendlynihilist commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span") "spam" not in "spa span sparql" and not (False) True and True True

Again, we need to execute the operation contained in round brackets "egg" > "span". Alphabetically, e is not bigger than s (that is, it comes first in order) so the output is False. Then we resolve not operators and, finally, the and operator.

HiImBono commented 5 years ago

Question

In the absence of round brackets, string operations have priority over boolean operations right? I was just wondering since "spam" not in "spa span sparql" is not between round brackets but ("egg" > "span") is. It does completely make sense to me if it works like this, otherwise you might have boolean operators operating on strings rather than booleans. If this is correct this would mean that the round brackets around ("egg" > "span") are redundant. Any body could confirm this by commenting the hooray on my question?

ilsamoano commented 5 years ago

What is the boolean value of ​"spam" not in "spa span sparql" and not ("egg" > "span")​?

"spam" not in "spa span sparql" and not (False) ​ >> "egg" should be less than "span" true and not false true

SeverinJB commented 5 years ago

Applied with strings, the logical operator > ("egg" > "span") uses the alphabetic order for the operation, e.g. "a" < "b" is true, because the letter "a" is listed before "b" in the alphabetic order. Based on this rule, the computation "egg" > "span" is false.

"spam" not in "spa span sparql" and not ("egg" > "span") true and not(false) true and true true

Saraa04 commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span")

"spam" not in "spa span sparql" = True not ("egg" > "span") = not (False) True and not (False) = True and True => True

DavideApolloni commented 5 years ago

"spam" not in "spa span sparql" and not ("egg" > "span")

"spam" not in "spa span sparql" --> true ("egg" > "span") --> false

true and not (false) true and true true

essepuntato commented 5 years ago

@HiImBono

Answering your question, indeed all the comparisons will be executed before any other boolean operation.