publish solutions

This commit is contained in:
yann 2025-02-17 16:52:06 +01:00
parent e4fc3e18b1
commit 64b8207dbb
12 changed files with 197 additions and 17 deletions

View File

@ -1,2 +1,5 @@
name = input("Entrez votre nom : ") name = input("Entrez votre nom : ")
age = int(input("Entrez votre âge : ")) age = int(input("Entrez votre âge : "))
print(f"Bonjour, je m'appelle {name} et j'ai {age} ans.")

View File

@ -15,3 +15,19 @@ students = {
'Histoire': 78 'Histoire': 78
} }
} }
name = input("Entrez le nom de l'étudiant : ")
if name in students:
total = 0
print(f"Notes de {name}:")
for i in students[name]:
note = students[name][i]
total += note
print(i, ":", note)
print(f"Moyenne de {name} : {total/len(students[name])}")
else:
print("L'étudiant", name, "n'existe pas.")

View File

@ -1 +1,7 @@
words = ["python", "programmation", "langage", "ordinateur", "apprentissage"] words = ["python", "programmation", "langage", "ordinateur", "apprentissage"]
comprehension = []
for i in words:
comprehension.append((i, len(i)))
print(comprehension)

View File

@ -5,6 +5,7 @@ self.full_name=full_name
def displayName(self): def displayName(self):
print("Le nom complet est :", self.full_name) print("Le nom complet est :", self.full_name)
class other_class: class other_class:
def __init__(self, first_name, name): def __init__(self, first_name, name):
self.first_name = first_name self.first_name = first_name

View File

@ -1,5 +1,7 @@
def sum(a, b): def sum(a, b):
"""Returns the sum of the two given numbers"""
return a + b return a + b
def subtraction(a, b): def subtraction(a, b):
"""Returns the difference between first and second given numbers"""
return a - b return a - b

View File

@ -1,4 +1,10 @@
# Fonction calculate_average # Fonction calculate_average
def calculate_average(list):
"""Returns average of a given list"""
total = 0
for i in list:
total += i
return total / len(list)
# Exemple d'utilisation de la fonction # Exemple d'utilisation de la fonction
numbers = [10, 20, 30, 40, 50] numbers = [10, 20, 30, 40, 50]

View File

@ -1 +1,13 @@
## Écrivez votre code ici ! def square():
"""returns the square of the number"""
try:
a = input("Entrez un nombre : ")
result = int(a) * int(a)
return result
except ValueError:
print("Le paramètres doit être un nombre !")
return None
print(square())

View File

@ -1,5 +1,13 @@
def log_decorator(func): def log_decorator(func):
pass
def wrapper():
print("message avant")
result = func()
print("message après")
return result
return wrapper
@log_decorator @log_decorator
def function_test(): def function_test():

View File

@ -1,3 +1,15 @@
class Rectangle:
def __init__(self, width, length):
self.width = width
self.length = length
def calculate_area(self):
return self.width * self.length
def calculate_perimeter(self):
return 2 * (self.width + self.length)
# Test de la classe Rectangle # Test de la classe Rectangle
rectangle = Rectangle(5, 3) # 5:width & 3:length rectangle = Rectangle(5, 3) # 5:width & 3:length
print("Largeur:", rectangle.width) print("Largeur:", rectangle.width)

View File

@ -1 +1,26 @@
## Écrivez votre code ici ! ## Écrivez votre code ici !
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def display_details(self):
print(self.name, self.age)
class Employee(Person):
def __init__(self, name, age, salary):
self.salary = salary
super().__init__(name, age)
def display_details(self):
super().display_details()
print(self.salary)
test = Employee("test", 2, 2200)
test.display_details()

View File

@ -1 +1,32 @@
## Écrivez votre code ici ! ## Écrivez votre code ici !
class BankAccount:
"""A bank account"""
def __init__(self, account_holder, balance):
self.account_holder = account_holder
self.balance = balance
def deposit(self, amount):
"""Add money on bank account"""
if amount < 0:
print("Le crédit doit être positif")
else:
self.balance += amount
return self.balance
def withdraw(self, amount):
"""take money from bank account"""
total = self.balance - amount
if amount < 0:
print("Le montant doit être positif")
else:
if total < 0:
print("Le montant disponible est insuffisant")
else:
self.balance -= amount
return self.balance
def display_balance(self):
"""displays informations"""
print("Propriétaire du compte :", self.account_holder)
print("Solde :", self.balance)

View File

@ -4,8 +4,66 @@ class Book:
self.author = author self.author = author
self.year = year self.year = year
def __str__(self):
return self.title
def __repr__(self):
return str()
class Library: class Library:
def __init__(self): def __init__(self):
self.books = [] self.books = []
self.borrow_books = [] self.borrow_books = []
# Ajouter les méthodes ici # Ajouter les méthodes ici
def add_book(self, book):
"""add book to library"""
self.books.append(book)
def remove_book(self, book_title):
"""remove book from library"""
for i in self.books:
if i.title == book_title:
self.books.remove(i)
def borrow_book(self, book_title):
"""borrow a book from library"""
for i in self.books:
if i.title == book_title:
self.books.remove(i)
self.borrow_books.append(i)
def return_book(self, book_title):
for i in self.borrow_books:
if i.title == book_title:
self.borrow_books.remove(i)
self.books.append(i)
def available_books(self):
book_list = []
for book in self.books:
book_list.append(book.title)
return book_list
def borrowed_books(self):
book_list = []
for book in self.borrow_books:
book_list.append(book.title)
return book_list
bib = Library()
book1 = Book("Croc blanc", "Jack London", 1889)
book2 = Book("CRP", "Kant", 1781)
bib.add_book(book1)
bib.add_book(book2)
print(bib.available_books())
bib.borrow_book("CRP")
print(bib.available_books())
print(bib.borrowed_books())