Soon after I get all the basics, it will be time to pursue more advanced projects with Python. Maybe after this, I will have the means to generate my own remote income!
Today's topic is about repeating scripts on Python with for loops. The syntax of the for loop translates to "for each item in a condition, perform the script below once."
One such application with for loops is exponential function. Here is a rapid breakdown of the mentioned function below:
Insert a base number and power number.
The variable result stores the value 1.
For the number of times equal to the power number, multiply the base number with the result once.
The base number by the power of the power number is printed.
Departing from the topic of loops, we will now discuss about the 2D list. 2D lists are a list for lists. For example, with row and column IDs starting at 0, when you want to fetch the 2nd item in the 3rd list of a 2D list, type number_grid[2][1].
A nested loop is a loop inside a loop. See the image below for your reference.
The functions in coding languages were written from scratch. You can also create simple to complex functions exclusively for your own projects.
Another particular trait of Python is how it shuts down after its input() function receives an incompatible value.
To address this unwelcome feature of crashing errors, using the try and except function will intercept them in your file. Divide any number by zero from said block? "Invalid input."Â