0% found this document useful (0 votes)
22 views1 page

App Py

Uploaded by

Yahia Beghil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

App Py

Uploaded by

Yahia Beghil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def convert_pressure(value, from_unit, to_unit):

units = {"pascal": 1, "bar": 100000, "psi": 6894.76, "atmosphere": 101325}


return value * units[from_unit] / units[to_unit]

def convert_length(value, from_unit, to_unit):


units = {"meter": 1, "kilometer": 1000, "centimeter": 0.01, "millimeter":
0.001,
"mile": 1609.34, "yard": 0.9144, "foot": 0.3048, "inch": 0.0254}
return value * units[from_unit] / units[to_unit]

def convert_surface(value, from_unit, to_unit):


units = {"square_meter": 1, "square_kilometer": 1000000, "hectare": 10000,
"acre": 4046.86, "square_mile": 2590000, "square_yard": 0.836127,
"square_foot": 0.092903, "square_inch": 0.00064516}
return value * units[from_unit] / units[to_unit]

def get_input():
value = float(input("Entrez la valeur à convertir: "))
from_unit = input("Entrez l'unité d'origine: ").lower()
to_unit = input("Entrez l'unité de destination: ").lower()
return value, from_unit, to_unit

def main():
print("CONVERTISSEUR D'UNITÉS")
print("1. Pression")
print("2. Longueur")
print("3. Surface")
choice = input("Choisissez une catégorie: ")

value, from_unit, to_unit = get_input()

if choice == '1':
result = convert_pressure(value, from_unit, to_unit)
elif choice == '2':
result = convert_length(value, from_unit, to_unit)
elif choice == '3':
result = convert_surface(value, from_unit, to_unit)
else:
print("Choix non valide")
return

print(f"{value} {from_unit} est égal à {result} {to_unit}")

if __name__ == "__main__":
main()

You might also like