def ternary_expr(printer, ast):
    """Prints a ternary expression."""
    cond_str = printer.ast_to_string(ast["left"])  # printer.ast_to_string(ast["cond"])
    then_expr_str = printer.ast_to_string(ast["middle"])  # printer.ast_to_string(ast["thenExpr"])
    else_expr_str = printer.ast_to_string(ast["right"])  # printer.ast_to_string(ast["elseExpr"])
    return f'{cond_str} ? {then_expr_str} : {else_expr_str}'