You are on page 1of 2

Python Class Notes

Int (números)

Float (real numbers 3.27)

Bool (true or false)

Nonetype (special and has one value, none)

Type() to see the type of and object

Convert types of one type to another

Float (3) converts integer 3 to float 3.0

Int (3.9) truncates float 3.9 to integer 3

Print show a value into the console

** elevando un valor a una potencia

String (“palabras”)

Si uso comas (,) puedo usar los números como int si uso (+) debo convertir mis int a string

Control C para detener loops infinitos

For n in range (5): print (n); [el range 5 es el conteo de las vecs que entra en el loop n-1, 0,1,2,3,4]

N=0; while (n<5) print (n) n=n+1

Range (start, stop, step)

Len () is function used to retrieve the length of the string in parentheses

Indexing uses [ ] and number inside to give the character in that position, it stars at 0 and negative
one (-1) numbers always refers to the last value of the string.

Slice [star:stop:step} or [start:stop]

Guess and check

Guess is longer than the bisection search.


Bisection search code:
Cube=27

Epsilon=0.01

Num:guesses=0

Low=0

High=cube

Guess=(high+low)/2.0

While abs(guess**3-cube)>=epsilon:

If guess**3<cube:

Low=guess

Else:

High=guess

Guess=(high + low)/2.0

Num:guesses+=1

Print ´num_guesses= ´, num_guesses

You might also like