Comments (22)
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)
from 2020-2021.
@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.
from 2020-2021.
False
Work:
True and not (True)
True and False
False
from 2020-2021.
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
from 2020-2021.
"spam" not in "spa span sparql" -> T
not ("egg" > "span") -> not(F) -> T
"spam" not in "spa span sparql" and not ("egg" > "span") -> T
from 2020-2021.
“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]
from 2020-2021.
"spam" not in "spa span sparql" and not ("egg" > "span")
True and not ("egg" > "span")
True and not False
True and True
True
from 2020-2021.
"spam" not in "spa span sparql" and not ("egg" > "span")
True and not False
True and True
then True
from 2020-2021.
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
from 2020-2021.
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
from 2020-2021.
TRUE:
"spam" not in "spa span sparql" and not ("egg" > "span")
"spam" not in "spa span sparql" and not False
True and True
True
from 2020-2021.
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.
- NOT ("Egg"> "Span")
- NOT (FALSE) --> because the first letter of "Egg" comes before "S" in the alphabet, so it's not "greater than" the second one.
- TRUE
So, TRUE and TRUE= TRUE
from 2020-2021.
"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
from 2020-2021.
"spam" not in "spa span sparql" and not ("egg">"span")?
True and not (False)
True and True = TRUE
from 2020-2021.
This expression returns the boolean value True
from 2020-2021.
"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
from 2020-2021.
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.
from 2020-2021.
"spam" not in "spa span sparql" and not ("egg" > "span")
("spam" not in "spa span sparql") and not ( False )
(True) and (True)
True
from 2020-2021.
"spam" not in "spa span sparql" and not ("egg" > "span")
True and not False
True and True
True
from 2020-2021.
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`
from 2020-2021.
"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
from 2020-2021.
"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
from 2020-2021.
Related Issues (20)
- Lecture "Brute-force algorithms", exercise 5 HOT 15
- Lecture "Organising information: unordered structures", exercise 1 HOT 21
- Lecture "Organising information: unordered structures", exercise 2 HOT 19
- Lecture "Organising information: unordered structures", exercise 3 HOT 20
- Lecture "Recursion", exercise 1 HOT 19
- Lecture "Recursion", exercise 2 HOT 20
- Lecture "Divide and conquer algorithms", exercise 1 HOT 19
- Lecture "Divide and conquer algorithms", exercise 2 HOT 17
- Lecture "Divide and conquer algorithms", exercise 3 HOT 5
- Lecture "Dynamic programming algorithms", exercise 1 HOT 21
- Lecture "Dynamic programming algorithms", exercise 2 HOT 19
- Lecture "Organising information: trees", exercise 1 HOT 9
- Lecture "Organising information: trees", exercise 2 HOT 7
- Bonus exercise (AtariGo) HOT 2
- Lecture "Backtracking algorithms", exercise 1 HOT 6
- Lecture "Backtracking algorithms", exercise 2 HOT 5
- Lecture "Organising information: graphs", exercise 1 HOT 15
- Lecture "Organising information: graphs", exercise 2 HOT 14
- Lecture "Greedy algorithms", exercise 1 HOT 5
- Lecture "Greedy algorithms", exercise 2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 2020-2021.