Road to Masterball (1/4)

--Originally published at Programming Blog

Many of you might think, why Masterball? but in every game to get to the Masterball you need to learn the history of that region of Pokemon, and when you get the Masterball you are almost finishing the game (or in this blog, the class)

Anyway 1st!

 

  • Nesting of conditional statements

 

There may be a situation where you need double conditions to apply an action, and for this you can use the nested If construct, in a nested if construct, you can have an if/elif/else construct inside another if/elif/else construct

nesting

this is a graphic example of a nested conditional, and for coding it will be the same one if and inside another one for a more specific answer for example, giving a more precise answer or statement.

elif-code

nesting-conditionals

For more information about how to do it, and that’s how we learned was with this video, https://www.youtube.com/watch?v=8lR9JU-7bZA a rather easy to explain video that actually starts coding in 1:26.

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

 

 

2!

 

  • Use of recursion for repetitive algorithms

 

First of all to know this topic we need to know what is recursion, and that is a method of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call, if a function definition satisfies the condition of recursion, we call this function a recursive function.

But what does the recursive function?

Well first it has to fullfil an important condition to be used in a program: it has to terminate, a recursive function terminates, but can end up in an infinite loop if the base case is not met in the calls.

This might look difficult but on code it’s rather easy and

factorial
fibonacci
part1.png
(well.. for us haha)

An example would be Factorial and also the Fibonnaci

factorial fibonacci

if you still don’t know what or how this is a good video for more information https://www.youtube.com/watch?v=s12IdMeVpw0, it has 2 parts (the 2nd one is in the right part of the video).

http://www.python-course.eu/python3_recursive_functions.php

 

part1.png