In [1]:
inputted_numbers = input("Please, input some numbers seprated by a comma: ")
def simple_mean(inputted_numbers):
return float( sum(inputted_numbers) ) / float( len(inputted_numbers) )
print simple_mean(inputted_numbers)
Upgrade the function above to also ask the user the number of occurrences to calculate the average for. (e.g. if the user inputs 1,3,5,7,9 and as the second argument to function inputs 2, the function must result in (7+9)/2 = 8. If the user inputs the same numbers as a first argument, but inputs 3 as the 2nd, then the function must result in (5+7+9)/3=7)
In [4]:
inputted_numbers = input("Please, input some numbers seprated by a comma: ")
occurancy = input("Please, input the number of occurancies to calculate the mean for: ")
def rolling_mean(inputted_numbers,occurancy):
return float( sum(inputted_numbers[-occurancy:]) ) / float( len(inputted_numbers[-occurancy:]) )
print rolling_mean(inputted_numbers, occurancy)
Construct a function, which will generate a random number between 1 and 100 (both included). If this number is between 50 and 100 (not included) the function returns "Win", if it is between 1 and 50 (both included) the function returns "Loss" and if it is exactly 100 then the function returns "Draw". (Hint: to generate a random number, one should first import a package called random (i.e. import random) and then use the function randint from there (e.g. random.randint(x,y), where x=1 and y=100 in our case)
In [5]:
import random
number=random.randint(1,100)
def generator(number):
if 100 > number > 50:
return "Win"
elif 50 >= number >= 1:
return "Loss"
else:
return "Draw"
print(number)
print generator(number)
In [6]:
import pandas_datareader.data as web
stock_list = ["IBM","AAPL","MSFT"]
for stock in stock_list:
data = web.DataReader(stock,"google")
print( data.head(7) )
In [8]:
import pandas_datareader.data as web
import matplotlib.pyplot as plt
stock_list = ["IBM","AAPL","MSFT"]
for stock in stock_list:
data = web.DataReader(stock,"google")
plt.plot(data["Open"])
plt.show()