From f6b011124101daacfc94c03f1fe3fea6be54f37f Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 27 Nov 2023 14:49:47 +0100 Subject: [PATCH] course update of 2023-11-27 14:49:47 --- .obsidian/workspace.json | 12 +++--- Algo/B2/Exercises/String exercise.md | 62 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 Algo/B2/Exercises/String exercise.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index bdb1110..9830092 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -13,7 +13,7 @@ "state": { "type": "markdown", "state": { - "file": "Algo/B2/Exercises/Repetitive tutorial.md", + "file": "Algo/B2/Exercises/String exercise.md", "mode": "source", "source": false } @@ -85,7 +85,7 @@ "state": { "type": "backlink", "state": { - "file": "Algo/B2/Exercises/Repetitive tutorial.md", + "file": "Algo/B2/Exercises/String exercise.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -102,7 +102,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Algo/B2/Exercises/Repetitive tutorial.md", + "file": "Algo/B2/Exercises/String exercise.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -125,7 +125,7 @@ "state": { "type": "outline", "state": { - "file": "Algo/B2/Exercises/Repetitive tutorial.md" + "file": "Algo/B2/Exercises/String exercise.md" } } }, @@ -158,8 +158,9 @@ }, "active": "41ec48cdc3af71a1", "lastOpenFiles": [ - "Algo/B2/Exercises/Imperative exercise.md", "Algo/B2/Exercises/Repetitive tutorial.md", + "Algo/B2/Exercises/String exercise.md", + "Algo/B2/Exercises/Imperative exercise.md", "Prog/Collections.md", "Prog/Array.md", "Algo/B2/Exercises", @@ -189,7 +190,6 @@ "COM-ADMR/Séjour international EPITA.md", "Algo/B1/CM", "Electronic/Lecture 1.md", - "Architecture/Lecture 1.md", "Electronic", "Architecture", "English", diff --git a/Algo/B2/Exercises/String exercise.md b/Algo/B2/Exercises/String exercise.md new file mode 100644 index 0000000..9f18a8c --- /dev/null +++ b/Algo/B2/Exercises/String exercise.md @@ -0,0 +1,62 @@ +# String Exercises + +## Exercise 1.1 (Search) + +```python +def search(x: str, s:str) -> int: + """ + Function that counts the number + of occurences of a given character + in a string + + @params x (str): the keyword + @params s (str): the string + @return: (int): the number of occurences + """ + i = 1 + n = len(s) + for loop in range(n): + if s[n] == x: + i += 1 + return i + + def search2(s: str, x: str) -> int: + """ + Function that counts the number + of occurences of a given character + in a string + + @params x (str): the string + @return: (int): the occurence where is appear + """ + i = 1 + n = len(s) + for i in range(n): + if s[i] == x: + return i + return -1 +``` + +## Exercise 1.2 (Palindrome) + +```python +def palindrome(sentence: str) -> bool: + """ + Function that check if a number is a palindrome + @params sentence(str): the sentence to check + @return (bool): Either a palindrome or not + """ + newSentence = "" + oldSentence = "" + for element in sentence: + if element != " ": + newSentence = element + newSentence + for element in sentence: + if element != " ": + oldSentence += element + if newSentence == oldSentence: + return True + else: + return False +``` +