Don't wanna be here? Send us removal request.
Text
Mastery 21 - Dictionaries
Dictionaries are used to assign a value to a specific key. It is necessary to know the key to retrieve the value. Dictionaries in Python are defined by braces {}
For this code I decided to construct a dictionary. This dictionary has initially 5 key value pairs where the name of the album is the key.
2 notes
·
View notes
Text
Mastery 20 - File Input/Output
As we have seen before with WSQ09 (the photo above) and WSQ11 we can work with files in Python. The only thing we need to do is to open the file and then we can start working with it. We can read the lines of the file but these are taken as a default by Python (by saying something); we can also write something in a file. The basic commands you need to know to work with files are the following:
open() = opens the file
read()= reads the file
lower()= makes the entire file in lowercase letters
write()= makes you able to modify the file and write something in it.
close()= closes the file
0 notes
Text
Mastery 19 - Validated User Input
At some point working with your programming classes or experiences you will try your friends or someone else to try to use you programs, and you will know someone that will like to mess with the program. What do I mean?
If the program asks the user to introduce a number and they write a letter the program will mark an error. So the validated user input helps us to manage this kind of situation just as shown in the code in the photo.
0 notes
Text
Mastery 18 - Strings
Strings are what can be called a sequence of Unicode characters. In python we can recognize strings because they usually go inside single quotation marks or double quotation marks. In the particular case of Python, it does not have a character data type, this means that a single character is considered as a string with length 1.
But why are strings important? Every time you ask the user to introduce information so the program can do it’s job Python will receive that information as a string. As we have seen before we can change the property of these strings but they will always be necessary for the program to run properly.
0 notes
Text
Mastery 17 - Lists and Tuples
I have already worked with lists in WSQ07. What is the difference between lists and tuples? Both of them are ordered sequence of items that are separated by commas and they are written between brackets (for lists) or parenthesis (for tuples). Items in lists can be modified but items in tuples cannot be modified. Tuples are usually used to protect data while lists are usually used to stores data that can be provided by the user.
0 notes
Text
Mastery 16 - Which Repetition?
When do I need to use a while loop, a for loop or recursion?The application of each one depends on what you want to do and how these loops work:
- While: it will perform a specific activity or series of steps until a certain condition that it’s true turns to false. Useful when you need to repeat a series of state until a statement is fulfilled.
- For: it executes a set of steps once for each value or item in a list, tuple, set, etc.. Useful when you need to apply a series of steps on each value of a variable.
- Recursion: calls a function inside a function. This process requires a previous answer from this same process or another one.
0 notes
Text
Mastery 15 - Recursion
We have already talked a lot about functions. We can call functions whenever we need them but there is something known as recursion which basically means that a function calls itself. Recursion is useful when we want to simplify processes and it’s applied just by calling a function inside a function.
0 notes
Text
Mastery 14 - For
We have already checked one form of using loos. For is another form to use loops in programming but what’s the difference? For me the best way to understand what a for loop does is to use it with a list. The photo shows the code of one exercise I had to do for a exam (I actually don’t know if it’s okay to post it).
You can see in the comments of the program what does the program does but I will focus in the for loop inside the find_threes function.
The for loop in this case what does is to take every single value in the list and check if the if conditional indented it’s true, if it’s true it will follow with whatever we want to do with this value, but not true it won’t simply do anything with that value.
0 notes
Text
Mastery 13 - While
Sometimes when programming it’s necessary to work with calculation that require to be repeated multiple times, so instead of writing the same step multiple times we can use loops. One of the most common way to use these loops is the “while” loop. For me the perfect way to understand what the while loop does is to create a counter just like the one on the photo. What this loop does is that checks if the boolean condition after while is true or false, if true it follows the indented statements and repeat the process. If at some point the boolean condition it’s false it will automatically stops.
0 notes
Text
Mastery 12 - Nesting
We already checked the simplest form of a selection in a program which is the if statement. But when it is necessary to add more elements to judge and manage the data these conditionals can be nested, which means that the data will be managed based on is statements that can be true or false.
0 notes
Text
Mastery 11 - Conditionals
In order to make useful programs we need to know how to work with conditions and how it can change the “behavior” of the program and conditional statements are the ones that makes us life easier.
The simplest form of a selection in a program is the if statement. A boolean expression has to be written after the if and this statement it’s what we call condition, if this condition it’s true it will follow the intended statement but if it’s not true it will go on and check if the boolean statement after elif and will check if it’s true. Finally if the program checks all of the conditions and finds none of them it’s true it will automatically follow the intended statements after else.
0 notes
Text
Mastery 10 - Creating Modules
Now that we know what modules are I think it’s very useful for us to know that we can actually create modules by ourselves very easily.
The first thing to do is to create a file where we can put our functions, in this case I created a function called hello_name which allows me to print “Hello” and whatever the variable name gets assigned for.
After creating this file we have to save it and now we have to open another file in the same direction as our module file. For this new file we can do whatever we want. We first import our module by writing the words “import (the name of your module file)” now we can use our module.
0 notes
Text
Mastery 09 - Using Modules
The definition of a module is a file containing definitions and statements intended for use in other Python programs. Some of them come with Python as part of what is called as the standard library.
There are many modules in Python. So I posted here some examples of some modules.
Firstly we have the Mastery 03 code where we used a module to call the poem called “The Zen of Python”
Secondly we have a very funny module that is well known as the turtle module. This module will allow you to draw pictures as simple as a rectangle or as complex and funny as this code I posted.
Finally we have what a think it’s one of the preferred modules, the math one. With this module you can access many mathematical functions in case you need them.
0 notes
Text
Mastery 08 - Creating Functions
We have already worked many times with functions and that’s because it’s really important for us to understand what they are and how they function.
This time I posted the picture of the WSQ07 code so you see that I had already defined 2 functions that are called later in the program. The important thing about functions is that programmers can create them and define them as they wish so they can work with their program. the name of a function works as a variable so be careful to not to name 2 functions the same because it will not work.
0 notes
Text
WSQ12 - SciLab
For this exercise we were asked to download and “play” with this platform called SciLab but... what is SciLab?
SciLab is an open source software that provides a powerful computing environment for engineering and scientific applications... did I mentioned it’s free?
This software has hundreds of mathematical functions, some of them are:
Maths & Simulation: Used for scientific and engineering applications like mathematical operations and data analysis.
Statistics: To perform data analysis and modeling
Optimization: To solve optimization problems (great explanation there)
Signal Processing: analyses, visualizes and filter signals in time and frequency domains.
2-D and 3-D Visualization: graphic functions to visualize, annotate and export data.
Xcos - Hybrid dynamic systems modeler and simulator: used to model control systems, hydraulic circuits, mechanical systems and more
0 notes
Text
WSQ11 - Go Bananas
For this assignment we worked again with files but this time the purpose of the program is to display the amount of times a specific word appears, in this case the word is “banana”. As you can see the text file is actually a song (the song is Waste - Foster the People) and I put the word BANANA randomly around the document. This program is made to count the word banana no matter how if its written like “BanANa” or “BANANA” or even maybe simply “banana”
0 notes