Introducción a la programación informática | Introduction to programming

Roguh

2021.11.24

Intro

Intro

Visit

What to Expect

What is programming?

La programación es el arte y la ciencia de traducir ideas en un programa

Programming is the art and science of translating a set of ideas into a program

Un programa es una lista de instrucciones exactas que puede seguir una computadora.

A program is a list of [exact] instructions a computer can follow.

What is programming, really?

youtu.be/Ct-lOOUqmyY

What is programming, really?

Computers:

Que pueden hacer? What can they do?

Visit

repl.it/languages/python3

Program 0

print("¡Hola Mundo!")
print("Hello, world!")

Program 1

name = "Alice"
message = "Hello," + name
print(message)
nombre = "Alice"
mensaje = "Hola" + nombre
print(mensaje)

Que va a hacer?

What will it do?

print quiere decir imprimir

Program 1: output

name = "Alice"
message = "Hello," + name
print(message)
nombre = "Alice"
mensaje = "Hola" + nombre
print(mensaje)

Output

Hello,Alice
HolaAlice

Program 1.1

name = "Alice"
message = "Hello, " + name
print(message)
nombre = "Alice"
mensaje = "Hola " + nombre
print(mensaje)

Output

Hello, Alice
Hola Alice

What is a programming language for?

para expresar un conjunto de instrucciones detalladas para una computadora digital

for expressing a set of detailed instructions for a digital computer

Read more here

Python

Fácil de aprender, comúnmente utilizado por científicos y empresas.

Easy to learn, commonly used by scientist and companies.

Uses?

In general:

Program 1.2

nombre = "Alice"
print("Hello, " + nombre + "!")

Program 1.2: output

nombre = "Alice"
print("Hello, " + nombre + "!")

Output

Hello, Alice!

Program 2: Two variables

nombre = "Zach"
saludo = "Goodbye"
print(saludo + nombre)

Exercise: ABBA

first = "a"
second = "b"
print(<YOUR CODE HERE>)

Debería imprimir | It should print:

abba

CodingBat!

codingbat.com -> Python -> String-1 -> make_abba

codingbat.com/prob/p182144

To do more coding bat you’ll need to learn about list/string slices and other Python concepts…

Program 3: Arithmetic and Numbers

print(1 + 2 * 4 - 10 / 2)
print(2 ** 10)
print(195.51 // 10)

Program 3.1: A googol, notación científica | scientific notation

print(10 ** 100)
print(1e100)

Program 4: More math and modules/libraries

import math
radius = 145
print(math.pi * radius ** 2)

Program 5: Input

import math
user_input = input("Please enter the radius: ")
radius = float(user_input)
print(math.pi * radius ** 2)

Nombres para números | Names for numbers

float

número de coma/punto flotante | number with a “floating point”

1.1, 1.0, 99.124124, 0.000123, -50.05

integer, int

un número entero | whole number

1, -50, 0, 1000000000000

int(4.9) == 4

Exercise: calcule el volumen de un cubo | compute the volume of a cube

user_input = <YOUR CODE HERE>
side_length = float(user_input)
print(<YOUR CODE HERE>)

Exercise: calcule el volumen de un cubo | compute the volume of a cube

user_input = <YOUR CODE HERE>
side_length = float(user_input)
print(<YOUR CODE HERE>)

E/S | I/O

Periférico de entrada

Input/Output

Program 6: Dibuja con una tortuga | Drawing with Turtle

import turtle

turtle.forward(100)
turtle.color("red")
turtle.left(90)
turtle.forward(50)

How to run

Por favor crea una cuenta

You need a free account.

replit.com/languages/python_turtle

Program 7: Escalones | Stairs

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.right(90)

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.right(90)

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.right(90)

Program 8: Iteración | For loops (AKA iteration)

import turtle

for color in ['red', 'green', 'orange', 'blue']:
    turtle.color(color)
    turtle.forward(75)
    turtle.left(90)

Program 8.1: Escalones v2 | Stairs v2

Version 2

import turtle

for stair_count in range(40)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.right(90)

Program 8.2: Escalones de colores

import turtle

colors = ["red", "orange", "green", "blue", "purple"]

for stair_count in range(40):
    # Pick a color
    turtle.color(colors[stair_count % len(colors])
    # Draw 1 stair
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.right(90)

Exercise: Dibuja un cuadrado | Draw a square

import turtle

side_length = 100

<YOUR CODE HERE>

Exercise: Dibuja un cuadrado junto a un triángulo | Draw a square next to a triangle

import turtle

side_length = 100

<YOUR CODE HERE>

Trick: Speedup turtle when drawing complex things

turtle.speed("fastest")
turtle.tracer(False) # Esconde | Hide the turtle until it's done
turtle.update() # Enseñar | Show what the turtle drew

Squares

import turtlae

turtle.speed("fastest")
for square_number in range(35):
  turtle.left(10)
  for _ in range(4):
    turtle.forward(200)
    turtle.left(90)

triangles? octagons?

Advanced program: Recursividad | Recursion

import turtle

def koch_line(width, depth=0):
    if depth <= 0:
        turtle.forward(width)
    else:
        koch_line(width / 3, depth - 1)
        turtle.left(60)
        koch_line(width / 3, depth - 1)
        turtle.right(2 * 60)
        koch_line(width / 3, depth - 1)
        turtle.left(60)
        koch_line(width / 3, depth - 1)

def koch_snowflake(width=100, depth=1):
    for _ in range(3):
        koch_line(width, depth)
        turtle.right(180 - 60)

turtle.speed('fastest')
koch_snowflake(200, 3)
turtle.done()

Program 11: HTTP solicitudes | requests with requests library

import urllib
base_url = 'https://www.google.com/search?q='
query = urllib.parse.quote_plus('equipo academy')
response = requests.get(base_url + query)
print(response.status_code)
print(response.text)

response.status_code 200 is ok.

response.status_code ≥400 is error

Status codes

A warning!

La versión 2 de Python es muy antigua y ya no recibe actualizaciones.

Python version 2 is very old and no longer maintained.

print "Hello, world!"

Find newer resources!

Maintaining software

Receiving updates. Taking care of security problems.

A good sign

$ python --version
Python 3.9.7
>>> import sys
>>> sys.version
'3.9.7 (default, Oct 10 2021, 15:13:22) \n[GCC 11.1.0]'

A list of Python features

Some computer science and programming topics

Linux

My computer

Android

Videogames in Python

Use pygame at replit.com/new/pygame

askpython.com/python/examples/easy-games-in-python

realpython.com/pygame-a-primer/

Free and powerful: Unity and Godot.

Learning resources

Todo lo que necesitas es una computadora y tiempo.

All you need is a computer and time.

También puedes comenzar con JavaScript | You can also start with JavaScript

Se utiliza para crear sitios web y servidores web.

It is used to make websites and web servers.

Installing JavaScript

Program 12: JavaScript

let user_input = prompt("Enter the size of a square")
let number = Number(user_input)
let area = number * number
console.log("The area is " + area)

Projects

Encuentra un proyecto que te apasione.

Find a project you’re passionate about.

reddit.com/r/dailyprogrammer/

Aprende a aprender

Ser un autodidacta te ayudara

Learn to teach yourself

This will help you in college and in any other opportunities you may take.

As a professional, I have to learn new technologies every few years.

How to learn more

Other programming languages

Advice

How I would learn to code (if I could start over)