{}
BLACK NOVEMBER
Are you struggling to build your coding confidence or land your first job? Fast-track to your first pay-check. Start PRO
BLACK NOVEMBER
Fast-track to your first pay-check. Start PRO
run-icon
main.py
def parse_length(value: str) -> float: """Convert input like '10mm', '14cm', or '2m' into millimeters.""" value = value.strip().lower() #all code made by Joel or ThatOneDev-studio if value.endswith("mm"): return float(value[:-2]) elif value.endswith("cm"): return float(value[:-2]) * 10 elif value.endswith("m"): return float(value[:-1]) * 1000 else: raise ValueError("Please include a valid unit (mm, cm, m).") print("Include unit of measurement in the base and height, only mm, cm, and m") base_input = input("Enter the base of the triangle ") height_input = input("Enter the height of the triangle ") base_mm = parse_length(base_input) height_mm = parse_length(height_input) area_mm2 = (base_mm * height_mm) / 2 unit_out = input("What unit should the area be in? ").lower() if unit_out == "mm": area = area_mm2 unit_str = "mm2" elif unit_out == "cm": area = area_mm2 / 100 unit_str = "cm2" elif unit_out == "m": area = area_mm2 / 1_000_000 unit_str = "m2" else: raise ValueError("Invalid output unit.") print(f"The area of the triangle is {area} {unit_str}")
Output