course update of 2023-11-27 14:49:47
This commit is contained in:
parent
cd97f2b703
commit
f6b0111241
12
.obsidian/workspace.json
vendored
12
.obsidian/workspace.json
vendored
@ -13,7 +13,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/B2/Exercises/Repetitive tutorial.md",
|
"file": "Algo/B2/Exercises/String exercise.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": false
|
"source": false
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/B2/Exercises/Repetitive tutorial.md",
|
"file": "Algo/B2/Exercises/String exercise.md",
|
||||||
"collapseAll": false,
|
"collapseAll": false,
|
||||||
"extraContext": false,
|
"extraContext": false,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@ -102,7 +102,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outgoing-link",
|
"type": "outgoing-link",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/B2/Exercises/Repetitive tutorial.md",
|
"file": "Algo/B2/Exercises/String exercise.md",
|
||||||
"linksCollapsed": false,
|
"linksCollapsed": false,
|
||||||
"unlinkedCollapsed": true
|
"unlinkedCollapsed": true
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/B2/Exercises/Repetitive tutorial.md"
|
"file": "Algo/B2/Exercises/String exercise.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -158,8 +158,9 @@
|
|||||||
},
|
},
|
||||||
"active": "41ec48cdc3af71a1",
|
"active": "41ec48cdc3af71a1",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
"Algo/B2/Exercises/Imperative exercise.md",
|
|
||||||
"Algo/B2/Exercises/Repetitive tutorial.md",
|
"Algo/B2/Exercises/Repetitive tutorial.md",
|
||||||
|
"Algo/B2/Exercises/String exercise.md",
|
||||||
|
"Algo/B2/Exercises/Imperative exercise.md",
|
||||||
"Prog/Collections.md",
|
"Prog/Collections.md",
|
||||||
"Prog/Array.md",
|
"Prog/Array.md",
|
||||||
"Algo/B2/Exercises",
|
"Algo/B2/Exercises",
|
||||||
@ -189,7 +190,6 @@
|
|||||||
"COM-ADMR/Séjour international EPITA.md",
|
"COM-ADMR/Séjour international EPITA.md",
|
||||||
"Algo/B1/CM",
|
"Algo/B1/CM",
|
||||||
"Electronic/Lecture 1.md",
|
"Electronic/Lecture 1.md",
|
||||||
"Architecture/Lecture 1.md",
|
|
||||||
"Electronic",
|
"Electronic",
|
||||||
"Architecture",
|
"Architecture",
|
||||||
"English",
|
"English",
|
||||||
|
62
Algo/B2/Exercises/String exercise.md
Normal file
62
Algo/B2/Exercises/String exercise.md
Normal file
@ -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
|
||||||
|
```
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user