Skip to content

Instantly share code, notes, and snippets.

View Ad115's full-sized avatar

Andrés García García Ad115

View GitHub Profile
@Ad115
Ad115 / hello.py
Last active April 20, 2018 22:52
Hello world!
# First program in Python!
print("Hello world!")
# Import the turtle graphics module
import turtle
# Create a new turtle with the
# Turtle function of the turtle module
t = turtle.Turtle()
# 100 times...
for x in range(100):
t.forward(x) # Move forward x steps
# Import everything in the p5.py library
from p5 import *
def draw():
# On each frame...
if mouse_is_pressed:
fill(100) # Fill color gray
else:
fill(255) # Fill color white
@Ad115
Ad115 / biopython-sequence.py
Created June 5, 2018 03:26
Introduction to BioPython's Seq objects.
from Bio.Seq import Seq
# Create sequence object
my_sequence = Seq("AGTACACTGGT")
# Show the sequence object
print("Sequence:", my_sequence)
# The sequence was created with a generic alphabet.
# The alphabet tells us whether it is a DNA, RNA or
@Ad115
Ad115 / combination-abstraction.py
Last active September 16, 2018 23:48
Some means of combination and abstraction with Python
"""
Todo buen lenguaje de programación provee de al menos:
- Expresiones primitivas.
- Formas de combinar.
- Formas de abstraer.
A continuación vemos cómo se da eso en Python
"""
# --> Expresiones primitivas:
from turtle import Turtle
gamera = Turtle()
# Podríamos hacer muchas cosas padres con sólo repetir:
gamera.forward(50)
gamera.left(30)
gamera.forward(50)
gamera.left(30)
gamera.forward(50)
@Ad115
Ad115 / bools-app.py
Last active September 19, 2018 19:53
Una aplicación interesante de los booleanos
import turtle
import random
squirtle = turtle.Turtle()
for i in range(100):
# Haz un giro aleatorio
coin = random.choice([True, False])
angle = random.randint(0, 360)
@Ad115
Ad115 / module-op.py
Last active September 19, 2018 19:28
Un caso común de uso de el operador módulo en Python
import turtle
squirtle = turtle.Turtle()
# Los colores que usaremos
colors = ["red", "yellow", "blue", "orange", "green", "purple"]
n_colors = len(colors)
for i in range(100):
# Obtén el índice del color
@Ad115
Ad115 / sintax-error.py
Created October 1, 2018 19:10
Un ejemplo de un error de sintaxis
edad = int(input("Cuántos años tienes?")
if edad > 65:
print("Ya te jubilaste?")
elif edad > 21:
print("Ya eres un adulto.")
elif edad > 13:
print("Eres todo un joven adolescente.")
@Ad115
Ad115 / runtime-error.py
Created October 1, 2018 19:12
Ejemplo de un error de ejecución
edad = int(input("Cuántos años tienes?"))
if edad > 65:
print("Ya te jubilaste?")
elif tu_edad > 21:
print("Ya eres un adulto.")
elif edad > 13:
print("Eres todo un joven adolescente.")