Text text text negreta text text text cursiva text text text codi
text text text. Text text text negreta text text text cursiva text text text codi
text text text. ext text text negreta text text text cursiva text text text codi
text text text. Text text text negreta text text text cursiva text text text codi
text text text. Text text text negreta text text text cursiva text text text codi
text text text. ext text text negreta text text text cursiva text text text codi
text text text.
Cita cita cita cita cita cita negreta cita cita cita cita cita cursiva cita cita cita cita cita
codi
cita cita cita cita cita. Cita cita cita cita cita cita negreta cita cita cita cita cita cursiva cita cita cita cita citacodi
cita cita cita cita cita. Cita cita cita cita cita cita negreta cita cita cita cita cita cursiva cita cita cita cita citacodi
cita cita cita cita cita.
llista nivell 1
llista nivell 2
llista nivell 3
primer llista numerada
segon llista numerada
$$ z = \frac{x}{y} $$on $$ y =\sum_{i=0}^\infty \frac{1}{i!}x^i $$
for val in range(1,10,2):
print val
import turtle
def poligon(turtle, size, segments=4):
"""Draws a poligon with a turtle.
The segments have a length of size.
The number of segments can be also modified."""
angle = 360./segments
for i in range(segments):
turtle.forward(size)
turtle.left(angle)
wn = turtle.Screen() # Set up the window and its attributes
wn.screensize(250, 250)
wn.setup(width=280, height=280)
wn.bgcolor("gray")
wn.title("Test turtle")
alex = turtle.Turtle() # Create turtle named alex
size = 50 #Poligon size
alex.color('red', 'red')
poligon(alex, size) #Draw a red square
alex.color('blue', 'blue')
poligon(alex, size, 5) # Draw a blue pentagon
alex.color('orange', 'orange')
poligon(alex, size, 6) # Draw an orange hexagon
alex.color('yellow', 'yellow')
poligon(alex, 10, 40) # Draw nearly a yellow circle
wn.exitonclick()
raw_input()
¶# Verifiqueu que el següent codi demana un text per pantalla
# el retorna imprès
nom = input("Introdueix el teu nom: ")
print("> El teu nom és", nom)
Introdueix el teu nom: 12 > El teu nom és 12
matplotlib
¶%pylab inline
import matplotlib.pyplot as plt
from numpy import sqrt
x = range(0, 100)
plt.plot(x, sqrt(x), '-', linewidth=2)
Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['size'] `%matplotlib` prevents importing * from pylab and numpy
[<matplotlib.lines.Line2D at 0xaf46e16c>]
def solve_lin_sys(mat, vec):
"""Solves linear system mat·sol = vec
by direct inversion with numpy functions"""
sol = inv(mat).dot(vec)
return sol
A = array([[1., 2., 3.],[5., 3., 7.],[9., 1., 6.]])
b = array([1., 3., 5.])
x = solve_lin_sys(A,b)
print("A:" , A)
print("b:" , b)
print("x:", x)
A: [[ 1. 2. 3.] [ 5. 3. 7.] [ 9. 1. 6.]] b: [ 1. 3. 5.] x: [ 0.81818182 0.90909091 -0.54545455]
sympy
¶from IPython.display import Latex
import sympy
x=sympy.Symbol('x')
y=sympy.Symbol('y')
f=(x+2*y**3)**2
print("Standard output:")
print(f)
print(f.diff(y))
print(f.diff(x))
print(f.diff(x).diff(x))
print(f.diff(y).diff(x))
Latex(r'Latex output: \begin{eqnarray} f(x,y) = '+ sympy.latex(f)
+ r'\\ \frac{\partial f(x,y)}{\partial x}=' + sympy.latex(f.diff(x))
+ r'\\ \frac{\partial f(x,y)}{\partial y}=' + sympy.latex(f.diff(y))
+ r'\\ \frac{\partial^2 f(x,y)}{\partial^2 x}='+ sympy.latex(f.diff(x).diff(x))
+ r'\\ \frac{\partial^2 f(x,y)}{\partial x \partial y}='+ sympy.latex(f.diff(y).diff(x))
+ r'\end{eqnarray}')
Standard output: (x + 2*y**3)**2 12*y**2*(x + 2*y**3) 2*x + 4*y**3 2 12*y**2