-
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
-
Surplus Basics
Solution
class consumer:
def __init__(self,WTP):
self.WTP = WTP
def demand(self,price):
if price<=self.WTP:
return 1
else:
return 0
Let’s make an array of consumers with WTP for the values 1 through 10. Making arrays of class objects is an allowed part of coding!
consumerArray = [consumer(x) for x in range(1,11)]
Now if we wanted to see which people would buy the product at a given price, we could use another list comprehension from our array we just created and apply the function.
print([x.demand(5) for x in consumerArray])
Let’s iterate through all the possible prices and see which people will buy the product.
for price in range(1,11):
print([x.demand(price) for x in consumerArray])
Let’s find the aggregate demand at each price level.
for price in range(1,11):
print(sum([x.demand(price) for x in consumerArray]))
We can derive the demand curve from these 10 individuals like by creating an array for all of this
demandQ = []
for price in range(1,11):
demandQ.append(sum([x.demand(price) for x in consumerArray]))
And then we can plot it.
import matplotlib.pyplot as plt
prices = [x for x in range(1,11)]
plt.plot(prices,demandQ)
plt.show()
Challenge
Add a new function to our class which returns the surplus (hint: it will not be negative).
Prev
If Statements