Road to Masterball (2/4 or 1/2)!

--Originally published at Programming Blog

Check the 1st part to know why the name!

3!

 

  • When to use what type of repetition in a program

 

There’s a trick for what type of repetition you need in a program and it’s the following

For (loop)

You have a small part of your code that you want to repeat “x” number of times.

While (loop)

Keeps running the code until the condition is met, basically it has code and inside a condition.

Nested (loops)

Loop inside a loop

Break (not a loop but a helper)

To be free from a loop, you use the function “Break”.

Continue (not a loop, but to enter one)

Basically is to skip the rest of the statements in the current loop and to continue to the next part of the code (but can be used to enter another loop if you have a loop inside another loop).

http://www.pythonforbeginners.com/loops/for-while-and-nested-loops-in-python

meme-24

4!

 

  • Creation and use of Lists/Tuples (Python) or Arrays/Vectors (C++)

 

tuples

The creation of lists and tuples in python are rather easy and there is just a little difference in how to type it.

A tuple is written with parentheses, but you gotta name the list, and you can’t alter the data inside.

While a list, is written with square brackets and list their elements, and the difference is that you can actually alter the data inside.

if you require more information about this topic you can see a video about both topics.

https://www.youtube.com/watch?v=RVXIBZvg-W8

5!

Creation and use of strings

Strings are the most popular types in Python, we can create them simply by enclosing characters in quotes (‘’) python treats single quotes the same as double quotes, and the fast way to know what is creating string is coding (LUL)strings

so.. well that’s basically

the code line 4 and 5 is to print only a several substring (each letter is a substring)

if you require more information about this there is a good video about strings and more specific points about it https://www.youtube.com/watch?v=v6nD8f-J_XU ,  the coding starts at 1:24

https://www.tutorialspoint.com/python/python_strings.htm