import os import sys THETAS_FILE = "thetas.csv" def load_thetas(): if not os.path.exists(THETAS_FILE): return 0.0, 0.0 with open(THETAS_FILE) as f: lines = f.readlines() return float(lines[0]), float(lines[1]) def estimate_price(mileage, theta0, theta1): return theta0 + theta1 * mileage def main(): theta0, theta1 = load_thetas() if theta0 == 0.0 and theta1 == 0.0: print(f"Warning: no trained model found ({THETAS_FILE}), using θ0=0 θ1=0") else: print(f"Loaded θ0={theta0}, θ1={theta1}") while True: try: raw = input("\nMileage (km): ") mileage = float(raw) price = estimate_price(mileage, theta0, theta1) print(f"Estimated price: {price:.2f}") except ValueError: print("Please enter a valid number.") if __name__ == "__main__": try: main() except (KeyboardInterrupt, EOFError): print() sys.exit(0)