comp-think / 2020-2021

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. 2020/2021).
14 stars 9 forks source link

Lecture "Programming languages", exercise 2 #11

Open essepuntato opened 3 years ago

essepuntato commented 3 years ago

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

SarahTew commented 3 years ago

False

Work: True and not (True) True and False False

giorgiasampo commented 3 years ago

The Boolean value is TRUE because: -"spam" not in "spa span sparql" returns TRUE -"egg"> "span" returns FALSE (I summed the values of the letters according to the alphabetical order so e=5, g=7, s=19, p=16, a=1, n=14 so egg=19 and span=50) -not FALSE (result of previous operations) is TRUE -TRUE and TRUE is TRUE

edoardodalborgo commented 3 years ago

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

SarahTew commented 3 years ago

@giorgiasampo Thank you for your detailed explanation! I thought comparisons were purely just alphabetical by word (so whichever would come first in a dictionary was considered larger). Now I understand đź‘Ť

@essepuntato Thank you Professor Peroni. For anyone else that is confused about comparing strings I found this helpful explanation with a few simple exercises at the bottom to clear up the rules for comparing strings.

essepuntato commented 3 years ago

@SarahTew @giorgiasampo

Indeed the comparisons with strings are alphabetical, but the one that comes first in a dictionary is lesser than the other. E.g.:

"this string" > "another string" is True since "t" (first character of the first string) is greater than "a"(first character of the second string)

ChiaraCati commented 3 years ago

“spam” not in “spa span sparql” and not (“egg”>”span) -> “spam” not in “spa span sparql” and not False [first solve the part in the brackets] -> True and True [second step solve the not operations] -> True [finally solve the and operation]

fcagnola commented 3 years ago

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

dbrembilla commented 3 years ago

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

vanessabonanno commented 3 years ago

The answer is True: "spam" not in "spa span sparql" and not ("egg" > "span") True and not False [("egg" > "span") is False because egg comes before (<) "span" in alphabet] True and True True

AlessandraFa commented 3 years ago

The boolean value is 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

gabrielefiorenza commented 3 years ago

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

LuisAmmi commented 3 years ago

The boolean value is TRUE. First of all, we analyze the first condition about the two strings "spam" and "spa span sparql". "Spam" NOT in "spa span sparql" = TRUE

So, we check the second one.

So, TRUE and TRUE= TRUE

samuelespotti commented 3 years ago

"spam" not in "spa span sparql" and not ("egg" > "span") => false because "s" is greater than "e" (I think I understand) "spam" not in "spa span sparql" and not (False) True and True True

GiuliaMenna commented 3 years ago

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

True and not (False) True and True = TRUE

SusannaPinotti commented 3 years ago

This expression returns the boolean value True

yunglong28 commented 3 years ago

"spam" not in "spa span sparql" and not ("egg" > "span"). "spam" not in "spa span "sparql" is TRUE. not("egg">"span") is TRUE ("egg" greater than "span" is false and with not TRUE) TRUE and TRUE is TRUE so TRUE

laurentfintoni commented 3 years ago

The boolean value is True.

We solve the operation in () first. "egg" is not greater than "span" by alphabetical value, so the result is False. the first part is True ("spam" is not in the string). True and not False returns True.

penelopelask commented 3 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

lauratravaglini commented 3 years ago

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

True and not False True and True True

AleRosae commented 3 years ago

The Boolean value is True. Here is the procedure:

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

"spam" not in "spa span sparql" -> True

True and not ("egg" > "span")

("egg" > "span") -> False because "e" comes before "s"

True and not (False)

True and True

True`

IlaRoss commented 3 years ago

"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

enri-ca commented 3 years ago

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