Compte Rendu - Python Avancé
Compte Rendu
Nom: Hosny Mohamed Amine
Classe: ING CCV 3-2
Année Scolaire: 2024-2025
Nom du professeur: Mr. Sakouhi Mohamed
Matière: Python Avancé
Exercice 1:
Solution en Python pour compter les occurrences de chaque caractère:
```python
from collections import Counter
def count_characters(s):
counts = Counter(s)
for char, count in [Link]():
print(f'Le caractère : "{char}" figure {count} fois dans la chaine s')
count_characters("[Link]")
```
Exercice 2:
Programme pour vérifier si un mot est un palindrome:
```python
Page 1
Compte Rendu - Python Avancé
def is_palindrome(word):
return word == word[::-1]
mot = input("Entrez un mot: ")
if is_palindrome(mot):
print(f"{mot} est un palindrome.")
else:
print(f"{mot} n'est pas un palindrome.")
```
Exercice 3:
Afficher l'extension d'un fichier:
```python
def get_extension(filename):
return [Link]('.')[-1]
fichier = input("Entrez le nom du fichier: ")
print(f"L'extension du fichier est .{get_extension(fichier)}")
```
Exercice 4:
Transformer une URL en lien hypertexte:
```python
def to_hyperlink(url):
return f'<a href="{url}">{url}</a>'
Page 2
Compte Rendu - Python Avancé
url = input("Entrez une URL: ")
print(to_hyperlink(url))
```
Exercice 5:
Liste des mots communs entre deux chaînes:
```python
def common_words(s1, s2):
return list(set([Link]()) & set([Link]()))
s1 = "Python Java SQL"
s2 = "Java SQL C++"
print("Mots communs:", common_words(s1, s2))
```
... (Liste des corrections continue pour chaque exercice)
Page 3