This is an optional exercise to test your understanding of Python Basics. The questions tend to have a financial theme to them, but don't look to deeply into these tasks themselves, many of them don't hold any significance and are meaningless. If you find this extremely challenging, then you probably are not ready for the rest of this course yet and don't have enough programming experience to continue. I would suggest you take another course more geared towards complete beginners, such as Complete Python Bootcamp
In [4]:
price = 300
In [5]:
import math
math.sqrt( price )
Out[5]:
In [6]:
import math
math.sqrt( price )
Out[6]:
In [11]:
stock_index = "SP500"
In [13]:
stock_index[2:]
Out[13]:
In [14]:
stock_index = "SP500"
price = 300
In [15]:
print('The {quote} is at {price} today'.format(quote=stock_index,price=price))
Given the variable of a nested dictionary with nested lists:
stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}
Use indexing and key calls to grab the following items:
In [16]:
stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}
In [18]:
stock_info['sp500']['yesterday']
Out[18]:
In [19]:
stock_info['info'][1][2]
Out[19]:
In [25]:
def source_finder(str):
index = str.find('--')
return str[index + 2:]
In [26]:
source_finder("PRICE:345.324:SOURCE--QUANDL")
Out[26]:
In [38]:
def price_finder(str):
return str.upper().find('PRICE') != -1
In [39]:
price_finder("What is the price?")
Out[39]:
In [40]:
price_finder("DUDE, WHAT IS PRICE!!!")
Out[40]:
In [43]:
price_finder("The price is 300")
Out[43]:
In [44]:
price_finder("There are no prize is 300")
Out[44]:
In [45]:
def count_price(str):
return str.upper().count('PRICE')
In [46]:
s = 'Wow that is a nice price, very nice Price! I said price 3 times.'
In [49]:
count_price(s)
Out[49]:
In [51]:
s = 'ANOTHER pRiCe striNG should reTURN 1'
In [52]:
count_price(s)
Out[52]:
In [53]:
def avg_price(prices):
return sum(prices) / len(prices)
In [54]:
avg_price([3,4,5])
Out[54]: