importmathimportcmath# ====================================================
# OUTILS D'AFFICHAGE OPTIMISES (LARGEUR 52 CAR)
# ====================================================
defsep():print("-"*52)defdouble_sep():print("="*52)deftitre(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()defpause():sep()input(" >>> Appuie sur EXE pour continuer...")# ====================================================
# 1. PHYSIQUE : OSCILLATEUR
# ====================================================
defmenu_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 !")returnifm<=0:print("ERREUR : m doit etre > 0")returnw0=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 :")ifzeta==0:print(">> NON AMORTI")print(" Oscillation perpetuelle.")elif0<zeta<1:print(">> SOUS-AMORTI")print(" Oscillations qui diminuent.")wd=w0*math.sqrt(1-zeta**2)print(" Pseudo-puls wd :",round(wd,5))elifzeta==1:print(">> CRITIQUE")print(" Retour equilibre ultra-rapide.")else:print(">> SUR-AMORTI")print(" Retour lent, pas d'oscillation.")pause()# ====================================================
# 2. MATHS : EQUATION 2ND DEGRE
# ====================================================
defmenu_eq():titre("EQUATION AX^2 + BX + C = 0")try:a=float(input("a : "))b=float(input("b : "))c=float(input("c : "))except:returndelta=b**2-4*a*cprint("Delta =",delta)sep()s1=(-b-cmath.sqrt(delta))/(2*a)s2=(-b+cmath.sqrt(delta))/(2*a)print("SOLUTIONS :")ifdelta>0:print("REELLES :")print(" x1 =",round(s1.real,5))print(" x2 =",round(s2.real,5))elifdelta==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
# ====================================================
defmenu_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:returnres_v=0res_s=0nom=""ifch=='1':nom="SPHERE"r=float(input("Rayon r : "))res_v=(4/3)*math.pi*r**3res_s=4*math.pi*r**2elifch=='2':nom="CYLINDRE"r=float(input("Rayon r : "))h=float(input("Hauteur h : "))res_v=math.pi*r**2*hres_s=2*math.pi*r*h+2*math.pi*r**2elifch=='3':nom="CONE"r=float(input("Rayon r : "))h=float(input("Hauteur h : "))res_v=(1/3)*math.pi*r**2*hs=math.sqrt(r**2+h**2)res_s=math.pi*r*(r+s)elifch=='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)elifch=='5':nom="ELLIPSE"a=float(input("Demi-axe a : "))b=float(input("Demi-axe b : "))res_v=0res_s=math.pi*a*bprint("")# CORRECTION LIGNE 199 : Suppression de la f-string
print("--- RESULTATS :",nom,"---")ifch=='5':print(" Aire =",round(res_s,5))else:print(" Volume =",round(res_v,5))print(" Surface=",round(res_s,5))pause()# ====================================================
# 4. BIBLE
# ====================================================
defbible():whileTrue: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 : ")ifc=='0':breaksep()ifc=='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)")elifc=='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)")elifc=='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)|)")elifc=='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)")elifc=='5':print(">> JACOBIEN (dV)")print(" POLAIRE: r dr dth")print(" CYL: r dr dth dz")print(" SPHERE: rho^2 sin(phi) ...")pause()# ====================================================
# MAIN
# ====================================================
defmain():whileTrue: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 : ")ifchoix=='1':menu_osc()elifchoix=='2':menu_eq()elifchoix=='3':menu_geo()elifchoix=='4':bible()elifchoix=='5':breakexcept:passmain()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.