comp-think / 2019-2020

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. 2019/2020).
Other
12 stars 3 forks source link

Lecture "Programming languages", exercise 3 #11

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

Following the template in Listing 11, write in Python the algorithm proposed originally in Figure 4 of the chapter entitled "Algorithms" as a flowchart (which uses a different approach compared to the one discussed in the chapter about programming languages), and accompany such code with the related test function and some executions with varying values of input.

arcangelo7 commented 4 years ago

Screenshot (6)

Vince2992 commented 4 years ago

Ex3

NoonShin commented 4 years ago
def test_contains_word(first_word, second_word, bib_entry, expected):
    result = contains_word(first_word, second_word, bib_entry)
    if result == expected:
        return True
    else:
        return False

def contains_word(first_word, second_word, bib_entry):
    result = 0
    if first_word in bib_entry:
        result += 1
    if second_word in bib_entry:
        result += 1
    return result

print(test_contains_word('Shotton', 'Open', 'Shotton, D. (2013). Open Citations. Nature, 502: 295-297. doi:10.1038/502295a', 2))
print(test_contains_word('Citations', 'Science', 'Shotton, D. (2013). Open Citations. Nature, 502: 295-297. doi:10.1038/502295a', 1))
print(test_contains_word('References', '1983', 'Shotton, D. (2013). Open Citations. Nature, 502: 295-297. doi:10.1038/502295a', 0))
arimuti commented 4 years ago

image

FrancescoFernicola commented 4 years ago

Fist Algorithm Alternative

elisasilvad commented 4 years ago

Excercise 3 3

marcograsso commented 4 years ago

exercise 1

sntcristian commented 4 years ago

Screenshot (2)

This algorithm uses the string .count() method instead of the one described in the lectures.

noreanystrom commented 4 years ago

image

virginiaciambriello commented 4 years ago
first_algorithm
essepuntato commented 4 years ago

@elisasilvad, your code indeed works. However, it is not the direct translation of the flowchart in figure 4 indicated in the text of the exercise since the flowchart does not explicitly tell you to initialise the contains_first_word and contains_second_word variables as you did in your Python code.

giuliamanganelli commented 4 years ago

esercizio

morinigiu commented 4 years ago
Schermata 2019-12-08 alle 13 35 34