# -*- coding: utf-8 -*-
#----------------------
print()
print("                      Convertions barométriques")
print(" ---------------------------------------------------------------------")
#-----------------------------options
print()
print("          choisissez le chiffre de l'une des options suivantes")
print()
print(" bar.....................(bar): 1    MégaPascal...............(MPh): 6")
print(" millibar...............(mbar): 2    millimètre de mercure...(mmHg): 7")
print(" Pascal...................(Pa): 3    centimètre de mercure...(cmHg): 8")
print(" HectoPascal.............(hPa): 4    décimètre de mercure....(dmHg): 9")
print(" kiloPascal..............(kPh): 5    atmosphère (atm).........(at): 10")
print()
print(" ---------------------------------------------------------------------")
#-----------------------------choix
def choisir() :
    global choix
    
    choix = input("              Entrez le numéro de l'option choisie : ")
    print()
    try :
        choix = int(choix)
    except :
        print("        Vous devez taper uniquement un chiffre, rien d'autre")
        choisir() # tourniquet pour chiffre non conforme
    
    if choix < 0 :
        print("                  Erreur ce chiffre est négatif !")
        choisir()  # tourniquet pour chiffre négatif
        print()
        
    if choix == 0 :
        print("               Erreur se chiffre est trop petit !")
        choisir()  # tourniquet pour chiffre trop petit
        print()
    
    if choix > 10 :
        print("               Erreur se chiffre est trop grand !")    
        choisir()  # tourniquet pour chiffre trop grand
        print()
    
    return
#-----------------------------le nombre à calculer
def nmbre() :
    global nombre
    
    nombre = input("                 Entrer le nombre à calculer : ")
    print()
    try :
        nombre = float(nombre)
    except :
        print("        Vous devez taper uniquement un nombre, rien d'autre")
        nmbre() # tourniquet pour chiffre non conforme
    
    if nombre < 0.0 :
        print("                Erreur se chiffre est négatif !")
        nmbre()  # tourniquet pour chiffre trop petit
        print()
    
    return
#-----------------------------calcul tout ramener à hPa et mmHg
def calcul() :
    global choix
    global nombre
    global hPa
    global mmHg
#---------------------------------------------- 1 bar
    if choix == 1 :
        hPa = nombre * 1000.0
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 2 millibar
    if choix == 2 :
        hPa = nombre 
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 3 Pascal (= 100 000 Pa = 1 bar ≈ 750,0616827 Torr.)
    if choix == 3 :
        hPa = nombre
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 4 HectoPascal (= 1000 hPa = 1000 millibar ≈ 750,0616827 Torr.)
    if choix == 4 :
        hPa = nombre
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 5 kiloPascal
    if choix == 5 :
        hPa = nombre
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 6 MégaPascal
    if choix == 6 :
        hPa = nombre
        mmHg = nombre / 1.33322
        return
#---------------------------------------------- 7 millimètre de mercure
    if choix == 7 :
        mmHg = nombre
        hPa = nombre * 1.33322
        return
#---------------------------------------------- 8 centimètre de mercure
    if choix == 8 :
        mmHg = nombre
        hPa = nombre * 1.33322
        return
#---------------------------------------------- 9 décimètre de mercure
    if choix == 9 :
        mmHg = nombre
        hPa = nombre * 1.33322
        return
#---------------------------------------------- 10 atmosphère
    if choix == 10 :
        hPa = nombre * 1013.25
        mmHg = hPa / 1.33322
        return
#-----------------------------calculs arrondis
def arrondi() :
#    global choix
#    global nombre
    global bar
    global mbar
    global Pa
    global hPa
    global kPa
    global MPa
    global mmHg
    global cmHg
    global dmHg
    global at
    
    bar = round(hPa / 1000, 3)
    mbar = round(hPa, 3)
    Pa = round(hPa * 100, 3)
    hPa = round(hPa, 3)
    kPa = round(hPa / 10, 3)
    MPa = round(hPa / 10000, 3)
    mmHg = round(mmHg, 3)
    cmHg = round(mmHg / 10, 3)
    dmHg = round(mmHg / 100, 3)
    at = round(hPa / 1013.25, 3)
    
    return
#=================================
# Début de la lecture du programme
#-----------------------------déclaration des variables globales
global choix
global nombre
global bar
global mbar
global Pa
global hPa
global kPh
global MPh
global mmHg
global cmHg
global dmHg
global at
#-----------------------------initialisation des variables
choix = 0
nombre = 0.0
bar = 0.0
mbar = 0.0
Pa = 0.0
hPa = 0.0
kPa = 0.0
MPa = 0.0
mmHg = 0.0
cmHg = 0.0
dmHg = 0.0
at = 0.0
#-----------------------------[main]
choisir()
nmbre()
calcul()
arrondi()
#-----------------------------affichage
print()
print(" bar", bar)
print(" millibar", mbar)
print(" Pascal", Pa)
print(" HectoPascal", hPa)
print(" KiloPascal", kPa)
print(" MégaPascal", MPa)
print(" millimètre de mercure", mmHg)
print(" centimètre de mercure", cmHg)
print(" décimètre de mercure ", dmHg)
print(" atmosphère (atm) ", at)
#-----------------------------Sortie
print()
print("----------------------")
bye = (input ("Entrer pour Sortir...!"))
