Semaine 4, jour 5

This commit is contained in:
gauvainboiche
2026-01-16 17:13:01 +01:00
parent 54bb4d7628
commit 3f609ad139
38 changed files with 556 additions and 10 deletions

View File

@@ -0,0 +1 @@
3.12

View File

View File

@@ -0,0 +1,33 @@
class Fraction:
def __init__(self, numerateur, denominateur):
if denominateur == 0:
raise ValueError("Le denominateur ne peut etre nul")
if not isinstance(denominateur, int) or not isinstance(numerateur, int):
raise TypeError("Le numerateur/denominateur doit etre un entier")
self.numerateur = numerateur
self.denominateur = denominateur
@property
def quotient(self):
return self.numerateur / self.denominateur
print("Debut programme")
try:
tiers = Fraction(1, '0')
print(tiers.quotient)
except (ValueError, TypeError) as msg :
print(msg)
liste = [1,2,3,4]
dico = {'nom': "John"}
try:
print(dico['prenom'])
print(liste[7])
except LookupError as msg:
if isinstance(msg, KeyError):
print("La cle n'existe pas")
else:
print(msg)
print("Fin du programme")

31
Semaine_04/Divers/main.py Normal file
View File

@@ -0,0 +1,31 @@
from typing import TypedDict
def addition(*args): # args => tuple (2,3,4,5,6,6,6,7,7,8,9)
return sum(args)
print(addition(2,3,4,5))
livres = [
{"titre": "1984", "auteur": "Orwell"},
{"titre": "1983", "auteur": "Orwella"},
{"titre": "1985", "auteur": "Orwell"}
]
def display_infos(**kwargs): # kwargs => dict {"Titre": "Scandale", "Auteur": "Marlène Schiappa"}
resultats = []
for livre in livres:
if "auteur" in kwargs and kwargs["auteur"].lower() in livre["auteur"]:
resultats.append(livre)
if "titre" in kwargs and kwargs["titre"].lower() in livre["titre"]:
resultats.append(livre)
return resultats
infos: dict[str | int, str | int] = {"age": 23, "nom": "Albatar", "is_admin" : False}
class Criteres(TypedDict):
auteur: NotRequired[str]
titre: NotRequired[str]
print(CONSTANTES["db_name"])

View File

@@ -0,0 +1,42 @@
from datetime import date, time, datetime, timedelta
import pytz
date_2026 = date(2026, 1, 10)
print(date_2026)
today = date.today()
print(today)
hour = time()
print(hour)
hour = time(12, 34, 23)
print(hour)
hour_now = datetime.now().time()
print(hour_now)
day_now = datetime.now().date()
print(day_now)
timezone_paris = pytz.timezone("Europe/Paris")
timezone_moscou = pytz.timezone("Europe/Moscow")
timezone_pyongyang = pytz.timezone("Asia/Pyongyang")
heure_actuelle_paris = datetime.now(tz= timezone_paris)
heure_actuelle_moscou = datetime.now(tz= timezone_moscou)
heure_actuelle_pyongyang = datetime.now(tz= timezone_pyongyang)
print(heure_actuelle_paris)
print(heure_actuelle_moscou)
print(heure_actuelle_pyongyang)
date_15_jours = date.today() + timedelta(days= 15)
print(date_15_jours)
debut_voyage = datetime(2026, 1, 16, 12, 7, 18, tzinfo= timezone_paris)
fin_voyage = datetime(2026, 12, 25, 13, 56, 23, tzinfo= timezone_pyongyang)
print(debut_voyage - fin_voyage)
detail_voyage = debut_voyage - fin_voyage
print(detail_voyage.days)
print(detail_voyage.seconds)

View File

@@ -0,0 +1,9 @@
[project]
name = "divers"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"pytz>=2025.2",
]

23
Semaine_04/Divers/uv.lock generated Normal file
View File

@@ -0,0 +1,23 @@
version = 1
revision = 3
requires-python = ">=3.12"
[[package]]
name = "divers"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "pytz" },
]
[package.metadata]
requires-dist = [{ name = "pytz", specifier = ">=2025.2" }]
[[package]]
name = "pytz"
version = "2025.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/f8/bf/abbd3cdfb8fbc7fb3d4d38d320f2441b1e7cbe29be4f23797b4a2b5d8aac/pytz-2025.2.tar.gz", hash = "sha256:360b9e3dbb49a209c21ad61809c7fb453643e048b38924c765813546746e81c3", size = 320884, upload-time = "2025-03-25T02:25:00.538Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/81/c4/34e93fe5f5429d7570ec1fa436f1986fb1f00c3e0f43a589fe2bbcd22c3f/pytz-2025.2-py2.py3-none-any.whl", hash = "sha256:5ddf76296dd8c44c26eb8f4b6f35488f3ccbf6fbbd7adee0b7262d43f0ec2f00", size = 509225, upload-time = "2025-03-25T02:24:58.468Z" },
]