-
Notifications
You must be signed in to change notification settings - Fork 8
Lecture "Programming languages", exercise 3 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I tried but I am not sure.
|
` def contains_word(first_word, second_word, bib_entry):
print(contains_word("Problem", "Solving", "Miller, B. N., Ranum, D. L. (2011). Problem Solving with Algorithms and Data Structures using Python") output = 2 |
def test_words(first_word, second_word, bib_entry, expected_result): if result == expected_result: def words(first_word, second_word, bib_entry): if contains_first_word: print(test_words("move", "sole", "amor che move il sole", 2)) |
def test_contains_word (first_word, second_word, bib_entry, expected): def contains_word (first_word, second_word, bib_entry) : print (test_contains_word ("a", "b", "abcd", 2)) |
First and second test calls return True, the last one is False (the words are not found in bibentry due to case sensitiveness) |
def test_contains_word (first_word, second_word, bib_entry, expected_result) def contains_word (first_word, second_word, bib_entry) if contains_first_word and contains_second_word print (test_contains_word ("cura", "opera", "L'opera d'arte nell'epoca della sua riproducibilità tecnica (2012)/ W. Benjamin; a cura di F. Desideri"), 2) |
|
def test_contains_word(first_word, second_word, bib_entry, expected):
|
True |
|
|
I had some problems with the correct syntax of summing something to the variable. But I checked it and now it works. P.S. I think that we don't need a "If... else" statement here, we don't have an alternative set of instruction if the first if is false, the only thing that we have to do is going on to the next one. def test(first_word, second_word, bib_entry, expected):
|
def test_find_words(first_word, second_word, bib_entry, expected): result = contains_word(first_word, second_word, bib_entry) if result == expected: def contains_words(first_word, second_word, bib_entry): If second_word in bib_entry: else: elif second_word in bib_entry: result += 1 print(test_words("Peroni", "HTML", "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)) True, output 2 print(test_words)(“Mesmerizing”, “Miracle”, “Mesmerizing Ghost Doctor”)) True, output 1 |
def test_<text_contains_words>(<word1, word2, bib-entry>, expected): def <text_contains_words>(<word1, word2, bib-entry>): print(test_<text_contains_words>("Ada", "of", "Ada Lovelace was the daughter", 1)) |
def test_containing_word(firstword, secondword, bibentry, expected): if result == expected: def test_containing_word (firstword, secondword, bibentry): if firstword and secondword: print(test_containing_word("linguistics", "Alan", "Davies, Alan, and Catherine Elder, eds. The handbook of applied linguistics. John Wiley & Sons, 2008.", 2)) |
def contains_word(first_word, second_word, bib_entry): |
Hi all, Thanks for your comment. The idea of the exercise is just to convert literally the various widgets in the flowchart as proper constructs in Python. In particular – since several of you have done that – you should not use more than one result statements, because in the flowchart only one output widget is actually used. The solution of the exercise is shown as follows - and it is also available as Python file in the GitHub repository:
|
Following the template in Listing 11, write in Python the algorithm proposed originally in Figure 4 of the lecture notes entitled "Algorithms" as a flowchart, and accompany such code with the related test function and some executions with different input values.
The text was updated successfully, but these errors were encountered: