In [3]:
from math import *
x1 = input()
y1 = input()
x2 = input()
y2 = input()
delta_x = (x2 - x1)
delta_y = (y2 - y1)
distancia = sqrt(delta_x ** 2 + delta_y ** 2)
print("%.6f" % distancia)
In [7]:
ano = input()
if ano % 4 == 0:
print("Ano bissexto")
else:
print("Ano normal")
In [13]:
n_alunos = input()
nota_primeiro_aluno = input()
media = nota_primeiro_aluno
for i in range(n_alunos - 1):
nota = input()
media += nota
media = media / n_alunos
if nota_primeiro_aluno > media:
print("Aluno acima da media")
else:
print("Aluno precisa melhorar")
In [21]:
string = raw_input()
if str(string).lower() == str(string).lower()[::-1]:
print("E PALINDROMO")
else:
print("NAO E PALINDROMO")
In [31]:
import numpy as np
matrix = np.random.randint(0, 100, (3,3))
print matrix.dtype
print type(matrix)
print matrix.shape
In [40]:
import numpy as np
matrix = np.random.random((3,3))
print matrix
soma_linhas = matrix.sum(axis=1)
matrix = matrix / soma_linhas[:, np.newaxis]
print "\n\n", matrix
In [46]:
import numpy as np
matrix_A = np.array([[1,2,4],[5,3,7],[9,0,-8]])
matrix_B = np.array([9,18,1])
x = np.linalg.solve(matrix_A, matrix_B)
print x
# print np.allclose(np.dot(matrix_A, x), matrix_B)
In [50]:
%matplotlib inline
import numpy as np
import pylab as plt
def f(x):
return 2 * (x ** 2) + 3
x = np.linspace(-3, 3, 100)
y = f(x)
plt.xlabel("Eixo X")
plt.ylabel("Eixo Y")
plt.title("Grafico")
plt.plot(x,y)
Out[50]:
In [72]:
%matplotlib inline
import numpy as np
import pylab as plt
import math
def f(x):
return x**2 - 1
def g(x):
return np.exp(-x) * -x
def k(x):
return 1/x
x = np.linspace(-3, 3, 100)
y = f(x)
g = g(x)
k = k(x)
plt.xlabel("Eixo X")
plt.ylabel("Eixo Y")
plt.title("Grafico")
plt.grid(True)
plt.plot(x,y, '-b', label="Linha Azul")
plt.plot(x,g, ':y', label="Pontilhado Amarelo")
plt.plot(x,k, '--g', label="Tracejado Verde")
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()
In [80]:
%matplotlib inline
import numpy as np
import pylab as plt
import math
def f(x, e):
return x**e
x = np.linspace(2, 3, 100)
plt.xlabel("Eixo X")
plt.ylabel("Eixo Y")
plt.title("Grafico")
plt.grid(True)
styles = ['-b', '-k', '-y', '-g', '-r', '-m']
for i in range(6):
y = f(x, i)
label = "Linha " + str(i)
plt.plot(x,y, styles[i], label=label)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()
x = np.linspace(-3, 3, 100)
for i in range(6):
title = "Grafico x**" + str(i)
plt.title(title)
y = f(x, i)
plt.plot(x,y, styles[i])
plt.show()
In [ ]: