Name_________________ net-id _______ Name_________________ net-id _______ Name_________________ net-id _______ Name_________________ net-id _______
Questions based on the code in StockData.py, use that for answering questions.
[('2011-01-03', 604.35, 2365200), ('2011-01-04', 602.12, 1824500), ...]
This is obtained by printing the variable data. What are
the
types for data and data[0], respectively.
The data for each day includes the date, the closing price, and the
number of shares traded on that day, e.g.,
("2011-01-03", 604.35, 2365200) shows that the closing
price
was $604.35 and that 2,365,200 shares were traded. The maximum closing
price in a list obtained in the program can be determined
using
this list comprehension:
s used in this expression?
data in the program:
max_price initialized to 0?
max_date (more than one
may be correct)
mp = max(s[1] for s in data) vals = [tup[0] for tup in data if tup[1] == mp] max_date = vals[0]
mp = max(s[1] for s in data) index = [i for i,tup in enumerate(data) if tup[1] == mp] max_date = data[index[0]]
[tup[0] for tup in data if tup[1] == max(s[1] for s in data)][0]
avg_close