## WSQ14 Scilab

“Scilab is an open source, cross-platform numerical computational package and a high-level, numerically oriented programming language. It can be used for signal processing, statistical analysis, image enhancement, fluid dynamicssimulations, numerical optimization, and modeling, simulation of explicit and implicit dynamical systems and (if the corresponding toolbox is installed) symbolic manipulations.”

Source: https://en.wikipedia.org/wiki/Scilab. Yep, I used Wikipedia. I wasn’t in the mood of doing a long research to define Scilab.

Ok. Let’s start with the blog post.

Scilab is a really useful tool that will help me from NOW to make my math calculations. Besides I’m not quite good at math, It’s funny to use a math software with the programming knowledge that we already have.

Next Saturday is my math Final Exam. I’m definitely using this to check my exercises while I study. Tanks Ken to give us alternative tools and tips to survive our life in college, not just in your subject, but all the others.

Anuncios

## Quiz 7

Hey there! Let’s do the quiz #7.

“Create a function called dot_product that receives two lists of numbers (say list1 and
list2). The function returns what is the dot product of the two lists.

For full marks, if the lists are not the same size, then the function should return the
special value of NaN (which represents not a number). For Python, you can create this value with the expression: float(‘NaN’)”

Let me explain what is the dot product:

“In mathematics, the dot product, or scalar product (or sometimes inner product in the
context of Euclidean space), is an algebraic operation that takes two equal-length
sequences of numbers (usually coordinate vectors) and returns a single number.

Algebraically, it is the sum of the products of the corresponding entries of the two
sequences of numbers” Source: http://kenscourses.com/tc101winter2016/2016/04/quiz-07/ Heeere’s my code. I’ll explain it step by step.

First of all we define our function “dot_product” that will determine if the lists that my user gave me are the same length or not.

If not, the program will return the NaN result. This will tell the user that he/she is doing something wrong.

Otherwise, the code will do the dot product.

Here’s the link to my code. Enjoy coding!!!! Byeeee!

## WSQ13 Exam 2

Good morning! This blog post will explain the exercise that we did for Exam 2.

# Exercise number 1

Is about get the distance between two points. The code is the following one: O line 1 we import the “sqrt” function form the “math” library, we’ll need it because the main formula to get the distance is .

From line 2 to line 5, we ask the user for the four values to get the location of the points. Two values for “x” and two values for “y”.

Then, let’s convert them all to floats so we can manipulate them later.

The magic comes out in line 11, where we ‘translate’ the algebraic formula to a code. As you can notice, we use the ‘sqrt’ function on line 13, and finally, let’s print the result.

# Exercise number 2 Can you see the red chart? Yep, don’t do that. It was my failing code at the test.

## Quiz 6

Heeey there!!!!! Here’s my 6th quiz. Yup. I know It’s pretty late for it. I will reflect that on my rubric.

Aaaanyway, the fact is that the instructions were these: “Write a function to calculate the greatest common denominator of two positive integers using Euclid’s algorithm.”

Here’s the page if you want to check what’s the Euclid’s algorithm about: https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm So, here’s my code. Do you see the red chart? Dont’t do something like that. Your code won’t work.

I visited Emanuel’s blog and it was really helpful. I was kind of lost with this code.

I’ll be submitting a flowchart to explain it better.

Here’s my code if you want to check it out. Have a nice day!!!

🙂

## Partial Exam #1

Hey there! On this blogpost I’ll ulpoad the guide I did to study for my partial exam.

I read “Beginning Python”by Peter C. Norton, Salez Samuel, Dave Aitel, Eric Foster-Johnson, Leonard Richardson, Jason Diamond, Althea Parker and Michael Roberts.

I’ve been using this book during all the partial and it’s been really useful.

Well, here are my answers:

• How do we create comments and why?

With the # symbol. We write them through the program to indicate it’s development or just to write notes. Sometimes they’re used to skip parts of the code that are no longer needed.

• Explain the basic types and why there are different ones.

Data Types are categories for things within a program with which the program will work. There are different ones because you won’t use the same kind of objects every time you make a code. For example, if you need a number with a decimal part you’ll use a float, if you need an integer number, you’ll use the “int” type.  After a thing has a type, the program and the programmer knows what to do with it.

• How do we do basic input and output (text)?

Most of the times is necessary to assign a variable to each input so we can manipulate the information in the code. The “input” syntax looks like this:

X= input (“text”)

I always output information with the “print” command. The syntax is this:
print (“text”). If you’re adding variables to your output sentence, the syntax will be (“text” , variablenumber, “text”)

• How do you call functions?

When we have a function already defined, we assign a variable to it, and to call it, we just write: print (variable assigned) and our function will be executed.

• How do you define/create functions?

With the keyword “def” followed by the name that you want to give to your function. Be careful that you don’t give it the same name than another keyword or type in python, or your program will have some problems.
And then with the keyword return, where we write what that function will do

• How do you import and use libraries/modules?

Modules and libraries are a bunch of functions defined by the program or yourself, it depends on what you need to do in the current program you’re making. To call one of them, you need the keyword form (module) import (name of the function). Some of them just need the import keyword, and when you need the function, a dot and the specific action form that library. For example mat.sqrt. This will give you the square root of a number. Or the “from” random import randint will give you a random number in the range that you indicated. It depends on the module/library if you need the “form” keyword.

• Explain conditionals and usage of if, else (and elif for Python)

They’re needed to make decisions. They can be understand easier if we do an example with a flowchart.

“if” else and elif will allow the program to decide if a condition is true or not. If: evaluates the expression for the first time, if it’s not true, the program will go to run the Elif clause, and if both of them are false, the program will run the else clause.

The number of keywords that you’ll use in your program is equal to the number of conditions that you have in your code.

• Explain the workings and use of while loops

While loops are really useful when you’re programming a code that needs a part to run several times. The “while” will do what you indicate the program to do WHILE the condition is true. I’ll give an easy example. We’ll print the range number form 1 to 6.

Cont=1

Cont=int(cont)

While cont<=6:

Print (cont)

Cont=cont+1

Print: (“We’re done”)

So what the while the condition is true, the loop will run and the cont variable will increment it’s value each time the loop gets executed. http://looneytunes.wikia.com/wiki/That’s_All_Folks

## Pick a number (WSQ06)

This homework is really fun, because I need to create a game, so the user should guess which number the program did choose.

I didn’t know how to print/choose a random number, this website helped me out. The variable for the random number will be “x”

Alright, the range that I need is from 1 to 100. While proving the code, I’ll print the random number, but I’ll erase line 3 when I end up the homework. Then I need the user to guess my number, so I enter an input. And of course I assign it a variable, “y”. After that, we start with the “if” sentences. As we want our user to guess, we need to give him/her some clues. If he/she typed a lower or higher number, the program should print which is the problem.

Up to here, the result is this: Now I’ll say the user how many times he/she needed to guess the right number, and I’ll also comment line 3. Aaand there we go… 😀 Here’s my code, you can download it if you need/want to.

See ya..!

## WSQ02

Hey there! Apparently I didn’t do the easiest homework of the course: to print “Hello World”. So this blog will be about that.

First of all, we open the editor and the terminal window. And I’ll save my file as “hello1.py” Then, I use the “print” label, followed by the ‘Hello world’ sentence. And I run it in my python program.

Be sure your text has the correct syntax. (“text”)

That’s all for today. Have a nice day!