-
Notifications
You must be signed in to change notification settings - Fork 0
/
estimate.py
43 lines (34 loc) · 814 Bytes
/
estimate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
""" Reads the values from thetas file
Returns:
list -- list of theta values
"""
def read_thetas():
try:
thetas = open('thetas', 'r')
theta = thetas.read().split(',')
theta = [float(i) for i in theta]
thetas.close()
except:
return [0, 0]
return theta
""" Estimates the price of a car given its mileage
Arguments:
mileage {float} -- mileage of the car
Returns:
float -- estimated price of the car
"""
def estimate_price(theta0, theta1, mileage):
return theta0 + (theta1 * mileage)
""" Main function """
def main():
try:
mileage = input('Enter mileage: ')
mileage = float(mileage)
thetas = read_thetas()
price = estimate_price(thetas[0], thetas[1], mileage)
print('Estimated price: ', price)
except:
print('Error during estimation')
exit()
if __name__ == '__main__':
main()