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)

"""
Explanation: Homework 2 (solutions)
Problem 1
Construct a function, which will ask the user to input several numbers separated by commas
and will calculate their average. (e.g. if the user inputs 3,5,7 the function must result in 5).
End of explanation
"""


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)

"""
Explanation: Problem 2
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)
End of explanation
"""


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)

"""
Explanation: Problem 3
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)
End of explanation
"""


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) )

"""
Explanation: Problem 4
Create a list of 3 stocks (choose whatever stocks you want, e.g. ["IBM","AAPL","MSFT"]). Create a for loop that will iterate over the list, get the data of relevant stock and print the first 7 rows of the data.
End of explanation
"""


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()

"""
Explanation: Problem 5
Upgrade the for loop above. Now, instead of printing the data, the for loop should iterate over the list, get the data and plot it.
End of explanation
"""


