2.1 Mean calculator
In [10]:
set=raw_input("please enter numbers by comma ")
my_list=set.split(",")
n=len(my_list)
def mean(my_list):
sum=0
for i in range(n):
sum=sum+float(my_list[i])
i=i+1
return float(sum/n)
print "Mean is "+str(mean(my_list))
2.2 Moving mean
In [11]:
set=raw_input("please, enter numbers by comma ")
my_list=set.split(",")
number=raw_input('please,enter a number less than the length of the list ')
m=int(number)
n=len(my_list)
def moving_mean(my_list,number):
sum=0
for i in range(m):
k=n-int(i)-1
sum=sum+float(my_list[k])
i=i+1
return float(sum/m)
print "Moving mean is "+str(moving_mean(my_list,number))
2.3 Lottery
In [47]:
import random
x=random.randint(1,100)
def func(x):
if x>50 and x<100 :
return "Win"
elif x>=1 and x<=50:
return "Loss"
elif x==100:
return "Draw"
print func(x)
print (x)
2.4 Stock data(variant_1 for each stock separately)
In [48]:
import pandas_datareader.data as web
%matplotlib inline
In [49]:
import matplotlib.pyplot as plt
In [50]:
data1=web.DataReader("IBM","google")
In [51]:
data2=web.DataReader("AAPL","google")
In [52]:
data3=web.DataReader("MSFT","google")
In [53]:
data_list=["IBM","AAPL","MSFT"]
2.4 Stock data
In [54]:
for i in range(0,len(data_list)):
if data_list[int(i)]=="IBM":
print data1.head(7)
elif data_list[int(i)]=="AAPL":
print data2.head(7)
elif data_list[int(i)] =="MSFT":
print data3.head(7)
2.5 stock data graph
In [55]:
for i in range(0,len(data_list)):
if data_list[int(i)]=="IBM":
plt.plot(data1["High"],"red")
elif data_list[int(i)]=="AAPL":
plt.plot(data2["High"],"blue")
elif data_list[int(i)] =="MSFT":
plt.plot(data3["High"],"green")
In [ ]: