add: better input handling
This commit is contained in:
11
estimate.py
11
estimate.py
@@ -7,13 +7,20 @@ class Estimate:
|
|||||||
self.theta1 = 0
|
self.theta1 = 0
|
||||||
self.get_thetas()
|
self.get_thetas()
|
||||||
def get_thetas(self):
|
def get_thetas(self):
|
||||||
|
try:
|
||||||
with open(self.path, 'r') as file:
|
with open(self.path, 'r') as file:
|
||||||
self.data = pd.read_csv(file)
|
self.data = pd.read_csv(file)
|
||||||
self.theta0 = self.data["theta0"].iloc[0]
|
self.theta0 = self.data["theta0"].iloc[0]
|
||||||
self.theta1 = self.data["theta1"].iloc[0]
|
self.theta1 = self.data["theta1"].iloc[0]
|
||||||
|
except:
|
||||||
|
print("! Warning, no data has been found")
|
||||||
def estimate_price(self, mileage):
|
def estimate_price(self, mileage):
|
||||||
return self.theta0 + (self.theta1 * mileage)
|
return self.theta0 + (self.theta1 * mileage)
|
||||||
|
|
||||||
estimate = Estimate()
|
estimate = Estimate()
|
||||||
input = int(input("Please enter the mileage of your car: "))
|
try:
|
||||||
print("The estimated price for a", input, "kilometers car is :", estimate.estimate_price(input))
|
input = int(input("Please enter the mileage of your car: "))
|
||||||
|
except:
|
||||||
|
print("! Wrongs args format")
|
||||||
|
else:
|
||||||
|
print("The estimated price for a", input, "kilometers car is :", estimate.estimate_price(input))
|
||||||
|
|||||||
Reference in New Issue
Block a user