Comments (14)
The result is 2
A="HTML"
B="Peroni"
C="Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
score = 0
if A in C:
score += 1
elif B in C:
score += 1
else:
score = 0
print(score)
First test, is A in C? A is in C ---> score is increased by 1 --> 0 + 1 = 1
Second test, is B in C? B is in C ---> score is increased by 1 --> 1 + 1 = 2
Print(score) --> score is 2
from 2018-2019.
Following the flowchart in Fig. 4 I wrote a Python algorithm to find the result:
word1 = "Peroni"
word2 = "HTML"
bibentry = "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A.G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
result = 0
if word1 in bibentry:
result = result + 1
if word2 in bibentry:
result = result + 1
print (result)
The output is 2!
from 2018-2019.
The output will be "2" because both "HTML" and "Peroni" are in the bibliographic entry.
from 2018-2019.
The output is 2, given the fact that both HTML and Peroni are included in the bibliographic entry.
from 2018-2019.
The result (return) =2 since both the words "HTML" and "Peroni" are contained in the bibliographic entry.
from 2018-2019.
string1 = "Peroni"
string2 = "HTML"
bibentry = "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
if string1 or string2 in bibentry:
sum = 1
if string1 and string2 in bibentry:
sum = 2
else:
sum = 0
print (sum)
output: 2
from 2018-2019.
The output would be 2 because both strings/words, "Peroni" and "HTML", are included in the bibliographic entry, if you consider them both together. If instead you consider just one of them at time, the output would be 1.
from 2018-2019.
Both the words "Peroni" and "HTML" are contained in the bibliographic entry, so the output is 2.
from 2018-2019.
Bibliographic entry:
"Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
Both "HTML" and "Peroni" appear in the bibliographic entry, therefore the result is 2.
from 2018-2019.
A = "Peroni"
B = "HTML"
Def = "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
if A or B in Def:
sum = 1
if A and B in Def:
sum = 2
else:
sum = 0
print `(sum)`
output = 2
from 2018-2019.
“Peroni” and “HTML” are both parts of the input value. Hence, the result is 2.
Followed Path: … —> Initialise the result value to 0 —> The first word (“Peroni”) is in the bibliography entry —> Sum 1 to the result value —> The second word (“HTML”) is in the bibliography entry —> Sum 1 to the result value —> Return the result value (“2”) —> …
from 2018-2019.
@delfimpandiani, while the answer to the exercise is correct, the pseudocode describe a different flow, in particular in the instruction:
elif B in C:
This instruction will be executed if and only if the condition in the previous if
is not satisfied. Thus, following your code, the actual result that will be returned in this case should be 1.
Similarly, @simayguzel and @ilsamoano, the two if
in your pseudocode make the whole process erroneus, even if you returned the corrent answer to the question. In fact, if you run your pseodocode with a different input, e.g. by substituting the first word "Peroni" with "Pippo", you will see that the algorithm will return 0 even if you expected to get a 1.
from 2018-2019.
Hi Prof,
thanks for the heads up.
I’ve tried to sub “Peroni” with “Pippo”,
but my code still gives 2 as a result, not 0 and neither 1.
A = "Pippo"
B = "HTML"
Def = "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
if A or B in Def:
sum = 1
if A and B in Def:
sum = 2
else:
sum = 0
print (sum)
2
If I change both the values of A and B the result is 0 despite “Computer” is a word in Def
A= "Computer"
B = "ojojo"
Def = "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132"
if A or B in Def:
sum = 1
if A and B in Def:
sum = 2
else:
sum = 0
print (sum)
0
from 2018-2019.
Sorry guys, you are totally right. I really don't know how I've read "elif" instead of "if".
Apologies.
from 2018-2019.
Related Issues (20)
- Lecture "Brute-force algorithms", exercise 3 HOT 13
- Lecture "Brute-force algorithms", exercise 4 HOT 16
- Lecture "Brute-force algorithms", exercise 5 HOT 12
- 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 17
- Lecture "Recursion", exercise 1 HOT 18
- Lecture "Recursion", exercise 2 HOT 20
- Lecture "Divide and conquer algorithm", exercise 1 HOT 12
- Lecture "Divide and conquer algorithm", exercise 2 HOT 5
- Lecture "Dynamic programming algorithms", exercise 1 HOT 15
- Lecture "Dynamic programming algorithms", exercise 2 HOT 8
- Lecture "Organising information: trees", exercise 1 HOT 4
- Lecture "Organising information: trees", exercise 2 HOT 4
- Lecture "Organising information: graphs", exercise 1 HOT 14
- Lecture "Organising information: graphs", exercise 2 HOT 12
- Christmas present game + bonus Python exercise
- Lecture "Backtracking algorithms", exercise 1 HOT 3
- Lecture "Greedy algorithms", exercise 1 HOT 2
- Question about an exercise from last year
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 2018-2019.