couteau_suisse.py

Created by teivaetienne

Created on January 29, 2026

7.28 KB


import math
import cmath

# ====================================================
# OUTILS D'AFFICHAGE OPTIMISES (LARGEUR 52 CAR)
# ====================================================
def sep():
    print("-" * 52)

def double_sep():
    print("=" * 52)

def titre(texte):
    double_sep()
    # Centrage manuel pour eviter les erreurs de calcul
    l = len(texte)
    espace = int((52 - l) / 2)
    print(" " * espace + texte.upper())
    double_sep()

def pause():
    sep()
    input("  >>> Appuie sur EXE pour continuer...")

# ====================================================
# 1. PHYSIQUE : OSCILLATEUR
# ====================================================
def menu_osc():
    titre("OSCILLATEUR HARMONIQUE")
    print("Equation : m.x'' + c.x' + k.x = 0")
    sep()
    
    try:
        m = float(input("Masse (m) : "))
        c = float(input("Amortissement (c) : "))
        k = float(input("Raideur (k) : "))
    except:
        print("ERREUR : Nombres requis !")
        return

    if m <= 0:
        print("ERREUR : m doit etre > 0")
        return

    w0 = math.sqrt(k / m)
    zeta = c / (2 * math.sqrt(k * m))

    titre("RESULTATS")
    # Utilisation de virgules pour eviter les erreurs de syntaxe
    print("Pulsation w0 :", round(w0, 5), "rad/s")
    print("Frequence f0 :", round(w0/(2*math.pi), 5), "Hz")
    print("Amortissement:", round(zeta, 5))
    sep()

    print("REGIME :")
    if zeta == 0:
        print(">> NON AMORTI")
        print("   Oscillation perpetuelle.")
    elif 0 < zeta < 1:
        print(">> SOUS-AMORTI")
        print("   Oscillations qui diminuent.")
        wd = w0 * math.sqrt(1 - zeta**2)
        print("   Pseudo-puls wd :", round(wd, 5))
    elif zeta == 1:
        print(">> CRITIQUE")
        print("   Retour equilibre ultra-rapide.")
    else:
        print(">> SUR-AMORTI")
        print("   Retour lent, pas d'oscillation.")
    
    pause()

# ====================================================
# 2. MATHS : EQUATION 2ND DEGRE
# ====================================================
def menu_eq():
    titre("EQUATION AX^2 + BX + C = 0")
    try:
        a = float(input("a : "))
        b = float(input("b : "))
        c = float(input("c : "))
    except:
        return

    delta = b**2 - 4*a*c
    print("Delta =", delta)
    sep()

    s1 = (-b - cmath.sqrt(delta)) / (2*a)
    s2 = (-b + cmath.sqrt(delta)) / (2*a)

    print("SOLUTIONS :")
    
    if delta > 0:
        print("REELLES :")
        print(" x1 =", round(s1.real, 5))
        print(" x2 =", round(s2.real, 5))
    elif delta == 0:
        print("DOUBLE :")
        print(" x0 =", round(s1.real, 5))
    else:
        print("COMPLEXES :")
        # Affichage manuel sans f-string
        print(" z1 =", round(s1.real,4), "+", round(s1.imag,4), "i")
        print(" z2 =", round(s2.real,4), "+", round(s2.imag,4), "i")
        
        sep()
        print("POLAIRE :")
        r, phi = cmath.polar(s1)
        print(" Mod (r) :", round(r, 5))
        print(" Arg (deg):", round(math.degrees(phi), 2))
    
    pause()

# ====================================================
# 3. GEOMETRIE : AIRES ET VOLUMES
# ====================================================
def menu_geo():
    titre("GEOMETRIE")
    print(" 1. Sphere")
    print(" 2. Cylindre")
    print(" 3. Cone")
    print(" 4. Tore")
    print(" 5. Ellipse (2D)")
    sep()
    
    try:
        ch = input("Choix : ")
    except:
        return
    
    res_v = 0
    res_s = 0
    nom = ""

    if ch == '1':
        nom = "SPHERE"
        r = float(input("Rayon r : "))
        res_v = (4/3) * math.pi * r**3
        res_s = 4 * math.pi * r**2
        
    elif ch == '2':
        nom = "CYLINDRE"
        r = float(input("Rayon r : "))
        h = float(input("Hauteur h : "))
        res_v = math.pi * r**2 * h
        res_s = 2*math.pi*r*h + 2*math.pi*r**2
        
    elif ch == '3':
        nom = "CONE"
        r = float(input("Rayon r : "))
        h = float(input("Hauteur h : "))
        res_v = (1/3) * math.pi * r**2 * h
        s = math.sqrt(r**2 + h**2)
        res_s = math.pi * r * (r + s)
        
    elif ch == '4':
        nom = "TORE"
        R = float(input("Grand Rayon R : "))
        r = float(input("Petit Rayon r : "))
        res_v = (math.pi * r**2) * (2 * math.pi * R)
        res_s = (2 * math.pi * r) * (2 * math.pi * R)
        
    elif ch == '5':
        nom = "ELLIPSE"
        a = float(input("Demi-axe a : "))
        b = float(input("Demi-axe b : "))
        res_v = 0
        res_s = math.pi * a * b

    print(" ")
    # CORRECTION LIGNE 199 : Suppression de la f-string
    print("--- RESULTATS :", nom, "---")
    
    if ch == '5':
        print(" Aire   =", round(res_s, 5))
    else:
        print(" Volume =", round(res_v, 5))
        print(" Surface=", round(res_s, 5))
        
    pause()

# ====================================================
# 4. BIBLE
# ====================================================
def bible():
    while True:
        titre("BIBLE PRIMITIVES u(x)")
        print("RAPPEL: (f(u))' = u' * f'(u)")
        print("        INT(u' * f(u)) = F(u)")
        double_sep()
        print(" 1. Puissances")
        print(" 2. Log & Expo")
        print(" 3. Trigo")
        print(" 4. Trigo Inverse")
        print(" 5. Jacobien")
        print(" 0. RETOUR")
        sep()
        
        c = input("Choix : ")
        if c == '0': break
        
        sep()
        if c == '1':
            print(">> PUISSANCE")
            print(" f: u' * u^n")
            print(" F: u^(n+1)/(n+1)")
            print("\n>> INVERSE")
            print(" f: u'/u^2  -> F: -1/u")
            print("\n>> RACINE")
            print(" f: u'/sqrt(u) -> F: 2sqrt(u)")

        elif c == '2':
            print(">> LOGARITHME (Important)")
            print(" f: u'/u")
            print(" F: ln(|u|)")
            print("\n>> EXPO")
            print(" f: u'*e^u -> F: e^u")
            print(" f: u'*a^u -> F: a^u/ln(a)")

        elif c == '3':
            print(">> TRIGO")
            print(" u'*cos(u) -> sin(u)")
            print(" u'*sin(u) -> -cos(u)")
            print(" u'/cos^2(u) -> tan(u)")
            print("\n>> INT(TAN)")
            print(" -ln(|cos(u)|)")

        elif c == '4':
            print(">> ARCTAN (Phase)")
            print(" f: u'/(1+u^2)")
            print(" F: arctan(u)")
            print("\n>> ARCSIN")
            print(" f: u'/sqrt(1-u^2)")
            print(" F: arcsin(u)")

        elif c == '5':
            print(">> JACOBIEN (dV)")
            print(" POLAIRE: r dr dth")
            print(" CYL:     r dr dth dz")
            print(" SPHERE:  rho^2 sin(phi) ...")
            
        pause()

# ====================================================
# MAIN
# ====================================================
def main():
    while True:
        print("\n" * 3)
        double_sep()
        print("   INGENIEUR KIT - NUMWORKS")
        double_sep()
        print(" 1. Oscillateur")
        print(" 2. Equation Delta")
        print(" 3. Geometrie")
        print(" 4. Bible Formules")
        print(" 5. Quitter")
        sep()
        
        try:
            choix = input("Choix : ")
            if choix == '1': menu_osc()
            elif choix == '2': menu_eq()
            elif choix == '3': menu_geo()
            elif choix == '4': bible()
            elif choix == '5': break
        except:
            pass

main()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.