From 1b77a885618eb77d77f8d6988a73d1ebd402fdb1 Mon Sep 17 00:00:00 2001 From: pvalarcher Date: Wed, 26 Oct 2022 18:22:20 +0200 Subject: [PATCH] fin cours 3 --- python/3/3Fic1.py | 5 +++-- python/3/annee.py | 8 ++++++++ python/3/books.csv | 3 ++- python/3/dessin.py | 4 ++++ python/3/ex31.py | 13 +++++++++++++ python/3/exo32.py | 17 +++++++++++++++++ python/3/exo33.py | 13 +++++++++++++ python/3/exo34.py | 26 ++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 python/3/annee.py create mode 100644 python/3/dessin.py create mode 100644 python/3/ex31.py create mode 100755 python/3/exo32.py create mode 100755 python/3/exo33.py create mode 100755 python/3/exo34.py diff --git a/python/3/3Fic1.py b/python/3/3Fic1.py index 71ab199..5b4ef7a 100644 --- a/python/3/3Fic1.py +++ b/python/3/3Fic1.py @@ -1,8 +1,8 @@ f = open ("books.csv", "r") max = 0 f.readline() -for row in f: - ligne = row.split(",") +for t in f: + ligne = t.split(",") if int(ligne[0]) > max: max = int(ligne[0]) @@ -18,3 +18,4 @@ f.write(enregistrement) f.close() + diff --git a/python/3/annee.py b/python/3/annee.py new file mode 100644 index 0000000..cd4d832 --- /dev/null +++ b/python/3/annee.py @@ -0,0 +1,8 @@ +f = open("books.csv", "r") +annee = input("Quelle année : ") +for r in f: + l = r.split(",") + if l[3] == annee+"\n": + print(str(l[1])) + +f.close() diff --git a/python/3/books.csv b/python/3/books.csv index 0bb84e9..72722e5 100644 --- a/python/3/books.csv +++ b/python/3/books.csv @@ -3,5 +3,6 @@ 1, A Brief History of Time, Stephen Hawking, 1988 2, The Great Gatsby , F. Scott Fitzgerald, 1922 3, The Man Who Mistook His Wife for a Hat, Oliver Sacks, 1985 -4, Pride and Prejudice , Jane Austen , 1813 +10, Pride and Prejudice , Jane Austen , 1813 5, Notre dame de Paris, Victor Hugo, 1834 +11, Les 3 mousquetaires, Alexandre Dumas,2022 diff --git a/python/3/dessin.py b/python/3/dessin.py new file mode 100644 index 0000000..455f323 --- /dev/null +++ b/python/3/dessin.py @@ -0,0 +1,4 @@ +import matplotlib.pyplot as plt +plt.plot([1,2,3,4]) +plt.ylabel('des nombres') +plt.show() diff --git a/python/3/ex31.py b/python/3/ex31.py new file mode 100644 index 0000000..0d60007 --- /dev/null +++ b/python/3/ex31.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +prenom = input("Entrer votre prénom: ") + +## si la longueur de prenom < 5 +## alors +if len(prenom) < 5: + nom = input("Entrer le nom de famille: ") + chaine = prenom + " " + nom ## concatenation avec un espace + print(chaine.upper()) +## sinon +else: + print(prenom.lower()) diff --git a/python/3/exo32.py b/python/3/exo32.py new file mode 100755 index 0000000..ceb80a2 --- /dev/null +++ b/python/3/exo32.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +## entrer un entier +## si il est entre 1 et 12 +## alors +## afficher la table de multiplication +## sinon +## rien + +n = int(input("Entrer un entier compris enter 1 et 12: ")) + +if n >= 1 and n <= 12: ## 1 ≤ n ≤ 12 + for i in range(1, 11): ## [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + r = i * n + print(str(i) + " * " + str(n) + " = " + str(r)) ## i * n = r + + \ No newline at end of file diff --git a/python/3/exo33.py b/python/3/exo33.py new file mode 100755 index 0000000..7a990e3 --- /dev/null +++ b/python/3/exo33.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +n = int (input("rentrer un nombre: ")) +coupdavant = n + +while n < 5: + coupdavant = n + n = int (input("rentrer un nombre: ")) + +print("Dernière valeur : ", coupdavant) + + + \ No newline at end of file diff --git a/python/3/exo34.py b/python/3/exo34.py new file mode 100755 index 0000000..4f8d7a3 --- /dev/null +++ b/python/3/exo34.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + + + +n1 = int(input("Entrer un entier: ")) +n2 = int(input("Entrer un entier: ")) +somme = n1 + n2 +reponse = input("voulez vous continuer: ") +while reponse == "oui": + n3 = int(input("Entrer un entier: ")) + somme = somme + n3 + reponse = input("voulez vous continuer: ") +print("La somme vaut ", somme) + + +## autre code +#n = int(input("Entrer un entier: ")) +#somme = n +#reponse = "oui" +#while reponse == "oui": +# n = int(input("Entrer un entier: ")) +# somme = somme + n +# reponse = input("voulez vous continuer: ") +#print("La somme vaut ", somme) + +