Creation and use of Lists/Tuples (Python)

--Originally published at angelmendozas

  • Lists are what they seem – a list of values. Each one of them is numbered, starting from zero – the first one is numbered zero, the second 1, the third 2, etc. You can remove values from the list, and add new values to the end. Example: Your many cats’ names.
  • Tuples are just like lists, but you can’t change their values. The values that you give it first up, are the values that you are stuck with for the rest of the program. Again, each value is numbered starting from zero, for easy reference. Example: the names of the months of the year.

Here’s a really good page to learn about them: http://sthurlow.com/python/lesson06/

Basically, you create lists when you can delete values, and change then as you wish in your code and tuples do not let you do this, they are constants we could say.


Creation and use of strings

--Originally published at angelmendozas

Strings are extremely useful in python programming, they can arrange data, return frases with data the user inputs, and several more things but in its most basic way you crate variables and ask the program to return whatever you want it to return.

potato1:’I love Canada’

potato2:’I hate Trump’

those are our variables, potato 1 and 2.

then we can ask the program to return part of the sentence as we know counting from zero (zero=one, the first word in the sentence)

print potato1[0:]

print potato2[6:]

Potato 1 will return ‘I love Canada’ and potato 2 will return ‘Trump’


Use of recursion for repetitive algorithms

--Originally published at angelmendozas

I saw this on: http://kenscourses.com/tc101winter2015/2015/use-of-recursion-for-repetitive-algorithms-6/

Basically, recursion in computer science is a method where the solution to a problem is based on solving smaller instances of the same problem.

Captura de pantalla 2016-11-07 a las 18.41.29.png

Recursion is multiplying n times n-1’s factorial f.e. if you choose 4 then the answer is 4×3! so its 4x3x2x1


When to use what type of repetition in a program

--Originally published at angelmendozas

Depends on the program you are writing, the if loop does or stops the desired task until what you programmed tells the program to do so.

While loop does a task as long as something happens to do that task, after that it stops.

A for loop can be combined with while but for a desired value the program does something.


Validated user input (ensure correct/expected data entry)

--Originally published at angelmendozas

To ensure the expected entry is correct you need to use a nested statement, so the program ensures the user input is exactly how you want it (well…the program).

Captura de pantalla 2016-11-07 a las 17.45.52.png

The program uses float bc there can be a positive or negative number in the input, then allows the user to write something with the input function, then as the comment says, it checks if the number is positive, negative or zero and prints whatever it is depending on the input.