Initial commit
This commit is contained in:
17
training/answers/02-language-basics/01-prints.adoc
Normal file
17
training/answers/02-language-basics/01-prints.adoc
Normal file
@ -0,0 +1,17 @@
|
||||
= Exercices
|
||||
|
||||
== Exercice 1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
print("La rue Rostand,")
|
||||
print(" se trouve au")
|
||||
print("Feu à droite")
|
||||
----
|
||||
|
||||
== Exercice 2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
print("Haut", "les", "cœurs", "!")
|
||||
----
|
65
training/answers/02-language-basics/02-variables.adoc
Normal file
65
training/answers/02-language-basics/02-variables.adoc
Normal file
@ -0,0 +1,65 @@
|
||||
= Exercices
|
||||
|
||||
== Exercice 1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
prenom = "Paul"
|
||||
temperature = 24.8
|
||||
paul_age = 30
|
||||
print(prenom, temperature, paul_age)
|
||||
----
|
||||
|
||||
== Exercice 2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
saisie = input("Saisissez du texte :")
|
||||
print(saisie)
|
||||
----
|
||||
|
||||
== Exercice 3
|
||||
|
||||
[source, python]
|
||||
----
|
||||
val1 = 53 * 46 + 13
|
||||
val2 = 99 > 13
|
||||
val3 = "Bonjour " + "chef"
|
||||
val4 = (59 * 62 + 13) / 6.5
|
||||
print(val1, val2, val3, val4)
|
||||
----
|
||||
|
||||
== Exercice A1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
distance = 42195
|
||||
print(distance // 1000) # nombre de kilomètres
|
||||
print(distance % 1000) # nombre de mètres restants
|
||||
----
|
||||
|
||||
== Exercice A2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
weight = 4_502_177
|
||||
print(weight // 1000000, "tonnes") # combien de groupes de 1000000 de grammes
|
||||
print((weight // 1000) % 1000) # combien de kilos restants, sans compter les tonnes
|
||||
print(weight % 1000) # combien de grammes restants
|
||||
----
|
||||
|
||||
== Exercice A3
|
||||
|
||||
[source, python]
|
||||
----
|
||||
saisie1 = input("Premier nombre :") # attention, je vais récupérer du texte
|
||||
saisie2 = input("Second nombre :")
|
||||
saisie1 = float(saisie1) # convertir en flottant
|
||||
saisie2 = float(saisie2) # convertir en flottant
|
||||
if saisie1 > saisie2:
|
||||
print(saisie1)
|
||||
else:
|
||||
print(saisie2)
|
||||
# Autre possibilité intéressante
|
||||
print(max(saisie1, saisie2))
|
||||
----
|
88
training/answers/02-language-basics/03-conditions.adoc
Normal file
88
training/answers/02-language-basics/03-conditions.adoc
Normal file
@ -0,0 +1,88 @@
|
||||
= Exercices
|
||||
|
||||
== Exercice 1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
roll = 5
|
||||
if roll > 4:
|
||||
print("Lancer réussi !")
|
||||
----
|
||||
|
||||
== Exercice 2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
text = "Bonjour"
|
||||
if text == "bonjouR":
|
||||
print("Bien le bonjour")
|
||||
----
|
||||
|
||||
== Exercice 2B
|
||||
|
||||
[source, python]
|
||||
----
|
||||
text = "Bonjour"
|
||||
if text == "Bonjour":
|
||||
print("Bien le bonjour")
|
||||
else:
|
||||
print("Je ne comprends pas !")
|
||||
----
|
||||
|
||||
== Exercice 3
|
||||
|
||||
[source, python]
|
||||
----
|
||||
value = 7
|
||||
if value >= 9:
|
||||
print("Élevé")
|
||||
elif value >= 7:
|
||||
print("Haut")
|
||||
elif value >= 4:
|
||||
print("Standard")
|
||||
else:
|
||||
print("Bas")
|
||||
----
|
||||
|
||||
== Exercice A1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
a1 = 4
|
||||
a2 = 7
|
||||
if a1 > 5 and a2 < 6:
|
||||
print("OK")
|
||||
else:
|
||||
print("Valeurs incorrectes")
|
||||
----
|
||||
|
||||
== Exercice A2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
a1 = 5
|
||||
a2 = 5
|
||||
if a1 > 5 or a2 < 6:
|
||||
print("Conditions suffisantes")
|
||||
else:
|
||||
print("Valeurs incorrectes")
|
||||
----
|
||||
|
||||
== Exercice A3
|
||||
|
||||
[source, python]
|
||||
----
|
||||
is_on = True
|
||||
saisie = input("Saisissez une commande (Marche ou Arrêt) :")
|
||||
if saisie == "Marche":
|
||||
if is_on is False:
|
||||
print("Allumage en cours…")
|
||||
else:
|
||||
print("Déjà allumé !")
|
||||
elif saisie == "Arrêt":
|
||||
if is_on:
|
||||
print("Extinction…")
|
||||
else:
|
||||
print("Déjà éteint !")
|
||||
----
|
||||
|
27
training/answers/02-language-basics/05-for-loop.adoc
Normal file
27
training/answers/02-language-basics/05-for-loop.adoc
Normal file
@ -0,0 +1,27 @@
|
||||
= Exercices
|
||||
|
||||
== Exercice 1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
for number in range(10):
|
||||
print(number)
|
||||
----
|
||||
|
||||
== Exercice 2
|
||||
|
||||
[source, python]
|
||||
----
|
||||
for number in range(10):
|
||||
if number % 2 == 0: # Est pair / reste 0 quand on fait la division entière
|
||||
print(number)
|
||||
----
|
||||
|
||||
== Exercice A1
|
||||
|
||||
[source, python]
|
||||
----
|
||||
for item1 in range(10):
|
||||
for item2 in range(item1):
|
||||
print(item1, item2)
|
||||
----
|
26
training/answers/02-language-basics/09-dictionaries.adoc
Normal file
26
training/answers/02-language-basics/09-dictionaries.adoc
Normal file
@ -0,0 +1,26 @@
|
||||
= Exercices sur les dictionnaires
|
||||
|
||||
'''
|
||||
|
||||
== Exercice A1 : compréhension de dictionnaire
|
||||
|
||||
*Rappel* : Convertir un dictionnaire en gardant les clés originales,
|
||||
mais y associer comme valeurs uniquement les températures.
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# Dictionnaire original
|
||||
meteo = {
|
||||
"Pau": (21.0, "Nuageux", 1015),
|
||||
"Gap": (20.3, "Dégagé", 1019),
|
||||
"Osny": (19.1, "Brouillard", 1015)
|
||||
}
|
||||
# Récupérer un dictionnaire dont les clés sont les noms de ville
|
||||
# et dont les valeurs sont uniquement les températures :
|
||||
# ici on conserve la clé, telle quelle, et comme chaque valeur
|
||||
# associée aux clés est toujours un tuple dont le premier élément est la
|
||||
# température, on peut s'y prendre ainsi :
|
||||
converted = {key: meteo[key][0] for key in meteo}
|
||||
# On affiche le résultat pour le vérifier
|
||||
print(converted)
|
||||
----
|
Reference in New Issue
Block a user