# -*- coding: utf-8 -*-
#----------------------
# calcul d'équivalence entre longueurs d'onde et fréquences
#---------------------------------------------------------
print()
print(" calcul de la fréquence par rapport à la longueur d'onde")
print(" calcul de la longueur d'onde par rapport à la fréquence")
print(" --------------------------------------------------------")
print()
#---------------------------------------- choisir l'option
def question() :
    print(" -------Choisissez l'option qui vous intéresse--------")
    print("   millihertz (mHz)....: .    millimètre (mm).....:  6") # 10 ** -3 = 0.001
    print("   centihertz (cHz)....: .    centimètre (cm).....:  7") # 10 ** -2 = 0.01
    print("   décihertz  (dHz)....: .    décimètre  (dm).....:  8") # 10 ** -1 = 0.1
    print("   hertz      (Hz).....: 1    mètre      (m)......:  9") # 10 **  0 = 1
    print("   décahertz  (dHz)....: .    décamètre  (dam)....: 10") # 10 **  1 = 10
    print("   hectohertz (hHz)....: .    hectomètre (hm).....: 11") # 10 **  2 = 100
    print("   kilohertz  (kHz.....: 2    kilomètre  (km).....: 12") # 10 **  3 = 1 000
    print("   mégahertz  (MHz)....: 3    mégamètre  (Mm).....: 13") # 10 **  6 = 1 000 000
    print("   gigahertz  (Ghz)....: 4    gigamètre  (Gm).....: 14") # 10 **  9 = 1 000 000 000
    print("   térahertz  (THz)....: 5    téramètre  (Tm).....: 15") # 10 ** 12 = 1 000 000 000 000
#    print("  pétahertz  (...)....: .    pétamètre  (Pm).....: 18") # 10 ** 15 = 1 000 000 000 000 000
#    print("  exahertz   (...)....: .    examètre   (Em).....: 19") # 10 ** 18 = 1 000 000 000 000 000 000
#    print("  zettahertz (...)....: .    zettamètre (Zm).....: 20") # 10 ** 21 = 1 000 000 000 000 000 000 000
#    print("  yottahertz (...)....: .    yottamètre (Ym).....: 21") # 10 ** 24 = 1 000 000 000 000 000 000 000 000
    print(" -----------------------------------------------------")
    print(" --les fréquences marquées d'un point n'existent pas--")
    print(" -----------------------------------------------------")
    return
#---------------------------------------- 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 > 18 :
        print("       Erreur se chiffre est trop grand !")    
        choisir()  # tourniquet pour chiffre trop grand
        print()
    return
#---------------------------------------- nombre entrée
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")
        nbr() # tourniquet pour chiffre non conforme
    
    if nombre < 0.0 :
        print("     Erreur se chiffre est négatif !")
        nbr()  # tourniquet pour chiffre trop petit
        print()
    return
#---------------------------------------- fréquences ramener tout en mégahertz
def freq() :
    global choix
    global nombre
    global fréquence
    
    if choix == 1 : # hertz
        fréquence = nombre / 1000000
    if choix == 2 : #  kilohertz
        fréquence = nombre / 1000
    if choix == 3 : # mégahertz
        fréquence = nombre
    if choix == 4 : # gigahertz
        fréquence = nombre * 1000
    if choix == 5 : # térahertz
        fréquence = nombre * 1000000
    return
#---------------------------------------- longueurs d'onde ramener tout en mètre
def lng_ond() :
    global choix
    global nombre
    global longueurOnde
     
    if choix == 6 :  # millimètre
        longueurOnde = nombre / 1000
    if choix == 7 :  # centimètre
        longueurOnde = nombre / 100
    if choix == 8 :  # décimètre
        longueurOnde = nombre / 10
    if choix == 9 :  # mètre
        longueurOnde = nombre
    if choix == 10 : # décamètre
        longueurOnde = nombre * 10
    if choix == 11 : # hectomètre
        longueurOnde = nombre * 100
    if choix == 12 : # kilomètre
        longueurOnde = nombre * 1000
    if choix == 13 : # mégamètre
        longueurOnde = nombre * 1000000
    if choix == 14 : # gigamètre
        longueurOnde = nombre * 1000000000
    if choix == 15 : # téramètre
        longueurOnde = nombre * 1000000000000
    return
#---------------------------------------- convertion
def conv() :
    global fréquence
    global longueurOnde
 
    if fréquence > 0 :
        longueurOnde = célérité / fréquence
    if longueurOnde > 0 :
        fréquence = célérité / longueurOnde
    return
#---------------------------------------- mettre tout aux valeurs réel
def réel() :
    global longueurOnde
    global fréquence
#------------------
    global hertz
    global kilohertz
    global mégahertz
    global gigahertz
    global térahertz
#------------------
    global millimètre
    global centimètre
    global décimètre
    global mètre
    global décamètre
    global hectomètre
    global kilomètre
    global mégamètre
    global gigamètre
    global teramètre
#-------------------
    hertz = fréquence * 1000000
    kilohertz = fréquence * 1000
    mégahertz = fréquence
    gigahertz = fréquence / 1000
    térahertz = fréquence / 1000000
#----------------------------------
    millimètre = longueurOnde * 1000
    centimètre = longueurOnde * 100
    décimètre = longueurOnde * 10
    mètre = longueurOnde
    décamètre = longueurOnde / 10
    hectomètre = longueurOnde / 100
    kilomètre = longueurOnde / 1000
    mégamètre = longueurOnde / 1000000
    gigamètre = longueurOnde / 1000000000
    teramètre = longueurOnde / 1000000000000
    return
#---------------------------------------- arrondir
def arrondir() :
    global hertz
    global kilohertz
    global mégahertz
    global gigahertz
    global térahertz
#------------------
    global millimètre
    global centimètre
    global décimètre
    global mètre
    global décamètre
    global hectomètre
    global kilomètre
    global mégamètre
    global gigamètre
    global teramètre
#-------------------
    hertz = round(hertz, 6)
    kilohertz = round(kilohertz, 9)
    mégahertz = round(mégahertz, 12)
    gigahertz = round(gigahertz, 15)
    térahertz = round(térahertz, 18)
#------------------
    millimètre = round(millimètre, 3)
    centimètre = round(centimètre, 4)
    décimètre = round(décimètre, 5)
    mètre = round(mètre, 6)
    décamètre = round(décamètre, 7)
    hectomètre = round(hectomètre, 8)
    kilomètre = round(kilomètre, 9)
    mégamètre = round(mégamètre, 12)
    gigamètre = round(gigamètre, 15)
    teramètre = round(teramètre, 18)
    return
#===========================================================================
# Début de la lecture du programme
#---------------------------------------- déclaration des variables globales
global choix
global nombre
global célérité
global fréquence
global longueurOnde
#------------------
global hertz
global kilohertz
global mégahertz
global gigahertz
global térahertz
#------------------
global millimètre
global centimètre
global décimètre
global mètre
global décamètre
global hectomètre
global kilomètre
global mégamètre
global gigamètre
global teramètre
#---------------------------------------- initialisation des variables
choix = 0
nombre = 0.0
célérité = 299.792458
fréquence = 0.0
longueurOnde = 0.0
#-----------------
hertz = 0.0
kilohertz = 0.0
mégahertz = 0.0
gigahertz = 0.0
térahertz = 0.0
#------------------
millimètre = 0.0
centimètre = 0.0
décimètre = 0.0
mètre = 0.0
décamètre = 0.0
hectomètre = 0.0
kilomètre = 0.0
mégamètre = 0.0
gigamètre = 0.0
teramètre = 0.0
#---------------------------------------- [main]
question()
choisir()
nmbre()
freq()
lng_ond()
conv()
réel()
arrondir()
#---------------------------------------- affiche
print("hertz........=", hertz, "Hz.")
print("kilohertz....=", kilohertz, "kHz.")
print("mégahertz....=", mégahertz, "mHz.")
print("gigahertz....=", gigahertz, "GHz.")
print("térahertz....=", térahertz, "THz.")
print("--------------------------------")
print("millimètre...=", millimètre, "mm.")
print("centimètre...=", centimètre, "cm.")
print("décimètre....=", décimètre, "dm.")
print("mètre........=", mètre, "m.")
print("décamètre....=", décamètre, "dam.")
print("hectomètre...=", hectomètre, "hm.")
print("kilomètre....=", kilomètre, "km.")
print("mégamètre....=", mégamètre, "Mm.")
print("gigamètre....=", gigamètre, "Gm.")
print("teramètre....=", teramètre, "Tm.")
#---------------------------------------- Sortie
print()
print("----------------------")
bye = (input ("Entrer pour Sortir...!"))
