# -*- coding: utf-8 -*-
#-----------------------------
'''
Les balances de précision offrent plusieurs unités de poids
-----------------------------------------------------------
Exemple:
1 g          gramme (fraction décimale de l’unité de base de la masse du kilogramme, système international)
1000 mg      milligramme (millième de gramme)
5.000 ct     carat (unité de mesure utilisée pour exprimer la pureté d'un métal précieux)
0.0353 oz    onces (Mesure de poids anglo-saxonne qui vaut la seizième partie de la livre)
0.0322 ozt   onces de troy (unité de mesure de masse, traditionnellement utilisée dans les pays anglo-saxons)
15.43 gn     céréal ou grains (unité de mesure de masse basée sur le poids d’un seul grain d’orge)
0.643 dwt    pennyweight (une unité de poids, 24 grains ou un vingtième d'once troy.)
0.200 tl     cuillère à café (En allemand Teelöffel, pluriel Teelöffel, abréviation TL)
0.200 tsp    cuillère à café (En anglais teaspoon, pluriel teaspoons, abréviation tsp)
-----------------------------------------------------------
Peser_précis est un petit programme de convertion.
============================================================
'''
#-----------------------------------------------------déclaration des variables
global choix
global quantité
global g
global mg
global ct
global oz
global ozt
global gn
global dwt
global tl

g = 0.0
mg = 0.0
ct = 0.0
oz = 0.0
ozt = 0.0
gn = 0.0
dwt = 0.0
tl = 0.0
#-----------------------------choix de l'unité de départ
def question_c() :
    global choix
    
    print("Choisir le chiffre de l'unité de départ")
    print("---------------------------------------")
    print()
    print(" g.....gramme..................= 1")
    print(" mg....milligramme.............= 2")
    print(" ct....carat...................= 3")
    print(" oz....onces...................= 4")
    print(" ozt...onces de troy...........= 5")
    print(" gn....céréal ou grains........= 6")
    print(" dwt...pennyweight.............= 7")
    print(" tl....cuillère à café.........= 8")
    print()
    choix = input("taper votre choix ")
    try :
        choix = int(choix)
    except :
        print("Vous devez taper uniquement des chiffres, rien d'autre.")
        print()
        question_c() # tourniquet pour réponse non conforme
    
    if choix < 1 :
        print("Ce chiffre est trop petit !")
        print()
        question_c() # tourniquet pour réponse non conforme
    
    if choix > 8 :
        print("Ce chiffre est trop grand !")
        print()
        question_c() # tourniquet pour réponse non conforme
    return
#-----------------------------quantité pour le calcul
def question_q() :
    global quantité
    
    print()
    quantité = input("taper la quantité de l'unité choisie à calculer ")
    try :
        quantité = float(quantité)
    except :
        print("Vous devez taper uniquement des chiffres, rien d'autre.")
        print()
        question_q() # tourniquet pour réponse non conforme
    
    if quantité == 0 :
        print("Ce chiffre est trop petit !")
        print()
        question_q() # tourniquet pour réponse non conforme
    return
#-----------------------------convertion de la quantité en gramme
def convertion() :
    global choix
    global quantité
    global g
    
    if choix == 1 :
        g = quantité
    if choix == 2 :
        g = quantité / 1000
    if choix == 3 :
        g = quantité / 5
    if choix == 4 :
        g = quantité * 28.349523125
    if choix == 5 :
        g = quantité * 31.1034768
    if choix == 6 :
        g = quantité / 15.432358352941
    if choix == 7 :
        g = quantité * 1.5551857669399
    if choix == 8 :
        g = quantité * 0.005
    return
#-----------------------------section calcul
def calcul() :
    global g
    global mg
    global ct
    global oz
    global ozt
    global gn
    global dwt
    global tl
    
    mg = g * 1000
    ct = g * 5
    oz = g / 28.349523125
    ozt = g / 31.1034768
    gn = g * 15.432358352941
    dwt = g / 1.5551857669399
    tl = g / 0.005
    return
#-----------------------------arrondir
# pas besoin d'arrondir
#-----------------------------[main]
question_c()
question_q()
convertion()
calcul()
#-----------------------------section impression
print()
print("gramme..................", g, "g")
print("milligramme.............", mg, "mg")
print("carat...................", ct, "ct")
print("onces...................", oz, "oz")
print("onces de troy...........", ozt, "ozt")
print("céréal ou grains........", gn, "gn")
print("pennyweight.............", dwt, "dwt")
print("cuillère à café........=", tl, "tl")
#-----------------------------------------------------------------------------------Sortie
print()
print("----------------------")
bye = (input ("Entrer pour Sortir...!"))
