Talking about Ken’s course

--Originally published at My B10g

What I liked:

i liked that ken is always trying to improve his teaching method and wants to receive suggestions from his students or get more close to them, socialize not only trow information to the air.

I also liked that he encouraged us to challenge and set goals to ourselves, to use today’s learning tools to learn by our own and be self-sufficient.

What can improve:

Even that the course can be very flexible to different kinds of learning, it’s still more flexible to some people talking about adaptation to different personalities.

Little advice: 

Instead of a final exam it would be nice to challenge the students with a team project of a subject each team choose since the second partial or something with no rubric and graded by the effort, external learnings, and everything else that can show the students compromise and vision.

Challenges are hard but students deserve to know what the career is about and see if that is what they want.


Creation and use of dictionaries in Python

--Originally published at My B10g

To begin it is important to know what is a dictionary, well a dictionary works similar to a list in which you can store information, but the dictionary will also organize it using this things called keys and not by order (there can’t be one key with to values, it would only save the last one). For example:

phonebook = {'Andrew Parson':8806336}
print(phonebook["Andrew Parson"])
...
8806336

Now that this is clear we need to know how to add or delete something, delete all, erase the dictionary, sort it, etc.

to delete an entry

del phonebook['Andrew Parson']

to add entries

phonebook['Sergio'] = 1234567

to change a value of an entry

phonebook['Sergio'] = 0

to erase all the entries

phonebook.clear()

to erase the hole dictionary

del phonebook

We also have build in functions to use with dictionaries, here I will write some:

len(dict)

this will give the number of items in the dictionary

str(dict)

this will transform the content in a string

dict.copy()

makes a copy from the dictionary

dict.get(key, default=None)

this will get the value assigned to a key

dict.has_key(key)

to check if a key exist, if it does return true.

dict.items()

to get tuples of all the entries in groups of key and value

dict.values()

returns a list of the values in the dictionary

sorry for the long post it has plenty information and for sure there is more so if you have more questions try this page: http://sthurlow.com/python/lesson06/


Creation and use of ranges in Python

--Originally published at My B10g

A range in python is created with the function range(). To use this you must know it´s rules. First, if the range if not specified will begin at 0 and will reach the integer before the parameter given. For example:

for i in range(3):
...     print(i)
...
0
1
2

Second, in case you pass two parameter it will take it as beginning and end in that order, but again ending one integer before the end and increasing by one as before. For example:

for i in range(3, 6):
...     print(i)
...
3
4
5

Third, when you pass three parameters, it will proceed this way: beginning, end, steps. This will mean that it will move from the beginning the number of steps you entered until it reaches the closest one to the end. For example:

for i in range(4, 10, 2):
...     print(i)
...
4
6
8

Note: In this function you can use any integer positive or negative but you can’t use floats.

http://giphy.com/gifs/SurZxNuuGJl96

.

.

.

.

.

.

.

.

.

Hacker tip:

if you want to use floats you can use this function:

def frange(start, stop, step):
...     i = start
...     while i < stop:
...         yield i
...         i += step

Shhhhhh don’t tell anyone.

You can see the original here:http://pythoncentral.io/pythons-range-function-explained/

It isn’t a well kept secret.


Reading and writing of text files

--Originally published at My B10g

When reading or writing a text file in python you can use the built in library of python to do so. The first step is to open the file and assign it to a variable for practical use (when you open a file you must define what you will be doing with it and to do so you need to use “r” for reading, “w” for writing, “a” appending or “r+”for reading and writing  ) . example:

file = open("hola.txt", 'r')

this mean I want to read file hola.txt

but to get what is in the file you can use:

file.read()

(to read all the file)

file.read(5)

(to read the first 5 characters)

file.readline()

(to read a complete line)

file.readlines()

(to read a list of strings of all the lines in the file)

To write in the file:

file.write("String")

(to write a string in a file)

file.writelines(variable)

(to write a list of strings separated by lines in the file )

When you do it this way you have to close the file at the end to optimize the program:

file.close()

But there are other ways to do it

using (with) there is no need to close the file.

with open("hello.txt", "w") as file:
	file.write("Hello World")

and you can do exactly the same things but writing less code.

 


Validated user input (ensure correct/expected data entry)

--Originally published at My B10g

Most of the times that you create a program you expect it to interact with the user, and by doing so they may be doing things that they aren’t supposed to, like writing word where they should write numbers or use special characters in strings, in this cases the computer will drop an error and will stop the program but how to prevent it from stoping and just let the user know he is doing something wrong? that is exactly what this topic is about.

As in many things in programing how you do it depends on the programer and there are plenty of ways to do so, so I will be explaining just the basic concept and to do so I will use an example.

def get_int(prompt):
    try:
        value = int(input(prompt))
    except ValueError:
        print("Sorry, I didn't understand that.")
        return get_int(prompt)

    if value < 0:
        print("Sorry, your response must not be negative.")
        return get_int(prompt)
    else:
        return value

to get started we need to know that we will need to create a loop (in this case the loop is created by calling the function again once it finds a mistake) because you want it to no matter how many times the user make a mistake the program should not stop until everything is correct, next we will need to check if the input is the correct type, to do so we will transform the input to an integer and in case it isn’t a number it would drop a mistake and for that we will use an except which will execute what should it do in case the program find a mistake of this type, in this

roses-are-red-violets-are-blue-if-a-had-a-brick-i
4pNDfd5CDT-2.png
Continue reading "Validated user input (ensure correct/expected data entry)"

Asesorias

--Originally published at My B10g

Si alguien se siente muy perdido o le gustaría tener alguien con quien hablar sus ideas puede buscarme y yo puedo intentar ayudarlo, no se mucho pero algo siento que se me da, hago esto en si porque siento que aprendo mejor cuando le explico a alguien lo que se o recien aprendi.

 


Creation and use of strings

--Originally published at My B10g

 

Strings in python are like lists where you can get each letter using its position making them easier to manage than in other languages.

although strings are letters you can also do operation with them, like;

+,*,[:],in, not in

you can add too strings using the + plus, or write something several times using * times, also you can take a substring from the strings using [:] and numbers to determine the length of the substring, or use “in” to check if a substring is inside the string in case that it does it returns True and in case of the “not in” its the oposite, it return True in case its not a substring.

example:

Captura de pantalla 2016-10-26 a las 16.24.22.png

apart from operation strings also have build-in methods which we can use to measure, search, compare, find if it’s a digit,etc.

String Methods

  • count (substring, begin, end): Counts and returns how many times the substring given was found in the String within the range given
  • endswith (suffix, begin, end): Returns true if a string ends with the suffix given
  • find (substring, begin, end): Determines if the substring is within the string and, if found, it returns its position. The method will return the first substring it finds, if not fount, it will return -1.
  • isdigit(): Returns true if the string contains only digits
  • len(string) returns the length of the string

 

Note: in a string you can’t print “\n” or “\t” because it adds an enter an a tab to the text respectively.


Creation and use of Lists/Tuples (Python)

--Originally published at My B10g

Tuples:

tuples gather information all together but you cannot change it´s order or add and remove things in it, to make a tuple it only requires a name and the use of () parenthesis.

example:

months = ('January','February','March','April','May','June',\
'July','August','September','October','November','  December')
print(months)

Note: you can use “\” to jump a line and organize it better

Lists:

List also save data but in the case of lists you can reorganize the values and add more  using List_name.append(‘added value’), you can also erase values using del List_name[#].

example:

cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester']
print (cats[2])
cats.append('Catherine')
del cats[1]

print (cats)

more at: http://sthurlow.com/python/lesson06/

Poem of the day:

roses_are_red_violets_are_blue_god


When to use what type of repetition in a program

--Originally published at My B10g

Types of repetition

The while loop: for indefinite number of repetitions(use more cpu)

captura-de-pantalla-2016-10-26-a-las-11-18-13

The for loop: for an specific number of repetitionscaptura-de-pantalla-2016-10-26-a-las-11-18-39

 

Nested loops – loops within loops: run a process which run other process and the first process will not run again until the nestes process finished runningcaptura-de-pantalla-2016-10-26-a-las-11-19-19

The recursion: repeats until it gets to one case which doesn’t call itself, used to reduce coding.

captura-de-pantalla-2016-10-26-a-las-11-22-24

more interesting stuff in: http://www.annedawson.net/Python3_Repetition_StringFormatting.htm

beautiful poem of the day

ef377f7286a930fb0c97b1a712f3d605

.

 


Use of Recursion for Repetitive Algorithms

--Originally published at My B10g

This is to simplify the coding and help us se it prettier and easier.

it can get a little bit weird when you think it too much but if it works you can see it ass a for  where your code will repeat until you tell him to stop.

i will explain this whit code

def factorial(n):

      if n == 1: 

            return 1

      else:

           return n * factorial(n-1)

in this case it stops at 1 where when the number gets to 1(the lowest factorial) it stop calling itself what make the code to stop.