-
Introduction 4
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
-
Production Possibilities Frontier 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Trade 3
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
-
Demand 4
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
-
Supply 2
-
Lecture5.1
-
Lecture5.2
-
-
Equilibrium 4
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
-
Curve Movements 4
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
-
Elasticity and Revenue 5
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Lecture8.4
-
Lecture8.5
-
-
Taxes 7
-
Lecture9.1
-
Lecture9.2
-
Lecture9.3
-
Lecture9.4
-
Lecture9.5
-
Lecture9.6
-
Lecture9.7
-
-
Consumer and Producer Surplus 8
-
Lecture10.1
-
Lecture10.2
-
Lecture10.3
-
Lecture10.4
-
Lecture10.5
-
Lecture10.6
-
Lecture10.7
-
Lecture10.8
-
-
Imports and Exports 4
-
Lecture11.1
-
Lecture11.2
-
Lecture11.3
-
Lecture11.4
-
-
Tariffs 2
-
Lecture12.1
-
Lecture12.2
-
Creating a Class Part 2
Solution
class car:
def __init__(self,brandName,gasTank,mpg):
self.brand = brandName
self.gasTank = gasTank
self.gas = gasTank
self.mpg = mpg
Classes also can have functions in them. Let’s create a function that fills up a car’s tank.
class car:
def __init__(self,brandName,gasTank,mpg):
self.brand = brandName
self.gasTank = gasTank
self.gas = gasTank
self.mpg = mpg
def fillUp(self):
self.gas = self.gasTank
Let’s see how this would work. We will create a car, then set it’s gas to 5 gallons, and finally use it’s fill up function.
ourCar = car("Ford",10,20)
print(ourCar.gas)
ourCar.gas = 5
print(ourCar.gas)
ourCar.fillUp()
print("After fill up")
print(ourCar.gas)
These functions can also take arguments, so if we wanted to change our fill up function, we could have it take an argument number of gallons and fill up the car that much.
Prev
Creating a Class
Next
If Statements