2017-12-27 00:48:04 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# fonctions.py : essai d'utilisation d'un package
|
|
|
|
|
|
|
|
# OpenClassrooms - Apprenez à programmer en Python - Modularité
|
|
|
|
# https://openclassroom/courses/apprenez-a-programmer-en-python/pas-a-pas-vers-la-modularite-2-2
|
|
|
|
|
2018-01-05 01:06:36 +00:00
|
|
|
"""Module de test, contient les fonctions crees durant le cours
|
|
|
|
OpenClassrooms - Apprenez à programmer en Python"""
|
2017-12-27 00:48:04 +00:00
|
|
|
|
|
|
|
def table(n, m=11):
|
2018-01-05 01:06:36 +00:00
|
|
|
"""Chapitre 1.7 - Modularite
|
|
|
|
Affiche la table de multiplication d'un nombre
|
2017-12-27 00:48:04 +00:00
|
|
|
de 1 * n
|
|
|
|
a m * n """
|
|
|
|
for i in range(1, m):
|
|
|
|
print(i,"x",n,"=",i * n)
|
|
|
|
|
|
|
|
# test de _table_
|
|
|
|
if __name__ == "__main__":
|
|
|
|
table(3)
|
2018-01-05 01:06:36 +00:00
|
|
|
|
|
|
|
def afficher_flottant(flot):
|
|
|
|
|
|
|
|
"""Chapitre 2.3 - Entre chaînes et listes
|
|
|
|
Affiche un nombre a virgule flottante tronque a 3 decimales
|
|
|
|
et remplace le point (.) par une virgule (,)"""
|
|
|
|
|
|
|
|
string = str(flot)
|
|
|
|
splited_string = string.split('.')
|
|
|
|
entier = splited_string[0]
|
|
|
|
|
|
|
|
if len(splited_string[1]) <= 3:
|
|
|
|
decimal = splited_string[1][:len(splited_string[1])]
|
|
|
|
else:
|
|
|
|
decimal = splited_string[1][:3]
|
|
|
|
|
|
|
|
flotant_formate = ','.join((entier,decimal))
|
|
|
|
print(flotant_formate)
|