Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/feed-rss2.php on line 8
‘#Lists’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Mon, 23 Nov 2015 13:15:27 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Masteries 20 and 23 – Loop for and creation and use of lists https://kenscourses.com/tc101fall2015/2015/masteries-20-and-22-loop-for-and-creation-and-use-of-lists/ Sat, 24 Oct 2015 15:54:00 +0000 http://kenscourses.com/tc101fall2015/?guid=afc677158768860813d1dfb5ba2c86d9 friends = ["maria","pepe","juan","roberto"]

creating lists

There are two ways of creting a list:
this_is_a_list = list()
this_is_a_list = []
Lists are created in the same way as a variable, but here you can choose for giving the variable a value of a list function or the value of an empty list.

using lists

If you want to take just one value of the list you have to use the variable with the position you want to take the value from. Let´s take the list of friends as an example, if i want to print "juan" i have to write this:
print (friends[2])
juan
As you can see "juan" is the third element on the list but i wrote 2. That happens because Python takes the first element as a 0, the second as a 1 and go on. If i want to take the fifth element on the list i have to write 4 because we are also counting the 0. If you want to add elements to the list you can use .append, it push the list one slot more and then add the value you want. For example if i want to add a new friend in my friends list:
friends.append("jose")
print (friends)
[maria,pepe,juan,roberto,jose]
Notice that i write .append right next to the list name and the put the value i want to add inside parenthesis.
There is also a way to count the number of elements inside a list. Is a function called len from lenght and is very easy to use. The function returns the number of elements and you can use it to do calculations. Let´s see how many friends i have:
print (len(friends))
5
You could also assign that value to a variable and use it later on.
There are a lot of more uses for a list but im not going to get to deep into it. This are the most common and useful but if you want to learn some more be sure to read the course book.

for loop

The for loop is a packed version of a while loop. The difference between a for loop and a while loop is that the for loop works with an iterator (a counter that works automatically), it works with lists and ranges (and more), and also the condition does not returns a boolean value . This is an example of the for loop:
for i in friends:
     print (i,"is my friend")
maria is my friend
pepe is my friend
juan is my friend
roberto is my friend
jose is my friend
The "i" in the for loop works exactly as a function, it takes a value from somewhere and sustitute that value inside the block. The condition is to take all the values of the list friends. The "i" is going to take the value from the first element and then sustitute that value inside the print function, when it ends it will move to the next value until the list is over.
Another way to use the for loop is to use a range. Instead of using a list as a condition we can tell "i" to take the value from a range of numbers. This is an example of a for loop with a range:
for i in range (1,3):
   print (i)
1
2
The loop printed only 1 and 2 but not 3 because the range is exclusive, this means that does not include the last number. It takes all the values from 1 to 3 without incluiding the 3, its like saying 1<=i>3 ("i" is greater or equal than 1 and less than 3 but not 3). Always add 1 to your real range because the loop is not going to take the last value, this is very important to undertand because by knowing you could avoid a lot of mistakes and hours of trying to fix a program.
You should also know that the "i" can be replaced by any other letter you want as you include it inside the loop.
There are some more iterators but these are the most common and useful for us. If you want to know more about this, you should read the course book.]]>
I want to start explaining the lists because to use the loop for you have to know how to create lists. First of all, a list is a variable that countains several values, they can be integers or strings. The list can be differentiated from a common variable because they use “[]” and the values are separated from commas. Here is an example:
friends = [“maria”,”pepe”,”juan”,”roberto”]

creating lists

There are two ways of creting a list:
this_is_a_list = list()
this_is_a_list = []
Lists are created in the same way as a variable, but here you can choose for giving the variable a value of a list function or the value of an empty list.

using lists

If you want to take just one value of the list you have to use the variable with the position you want to take the value from. Let´s take the list of friends as an example, if i want to print “juan” i have to write this:
print (friends[2])
juan
As you can see “juan” is the third element on the list but i wrote 2. That happens because Python takes the first element as a 0, the second as a 1 and go on. If i want to take the fifth element on the list i have to write 4 because we are also counting the 0. If you want to add elements to the list you can use .append, it push the list one slot more and then add the value you want. For example if i want to add a new friend in my friends list:
friends.append(“jose”)
print (friends)
[maria,pepe,juan,roberto,jose]
Notice that i write .append right next to the list name and the put the value i want to add inside parenthesis.
There is also a way to count the number of elements inside a list. Is a function called len from lenght and is very easy to use. The function returns the number of elements and you can use it to do calculations. Let´s see how many friends i have:
print (len(friends))
5
You could also assign that value to a variable and use it later on.
There are a lot of more uses for a list but im not going to get to deep into it. This are the most common and useful but if you want to learn some more be sure to read the course book.

for loop

The for loop is a packed version of a while loop. The difference between a for loop and a while loop is that the for loop works with an iterator (a counter that works automatically), it works with lists and ranges (and more), and also the condition does not returns a boolean value . This is an example of the for loop:
for i in friends:
     print (i,”is my friend”)
maria is my friend
pepe is my friend
juan is my friend
roberto is my friend
jose is my friend
The “i” in the for loop works exactly as a function, it takes a value from somewhere and sustitute that value inside the block. The condition is to take all the values of the list friends. The “i” is going to take the value from the first element and then sustitute that value inside the print function, when it ends it will move to the next value until the list is over.
Another way to use the for loop is to use a range. Instead of using a list as a condition we can tell “i” to take the value from a range of numbers. This is an example of a for loop with a range:
for i in range (1,3):
   print (i)
1
2
The loop printed only 1 and 2 but not 3 because the range is exclusive, this means that does not include the last number. It takes all the values from 1 to 3 without incluiding the 3, its like saying 1<=i>3 (“i” is greater or equal than 1 and less than 3 but not 3). Always add 1 to your real range because the loop is not going to take the last value, this is very important to undertand because by knowing you could avoid a lot of mistakes and hours of trying to fix a program.
You should also know that the “i” can be replaced by any other letter you want as you include it inside the loop.
There are some more iterators but these are the most common and useful for us. If you want to know more about this, you should read the course book.

]]>
https://creativecommons.org/licenses/by/4.0/
WSQ10 – Lists https://kenscourses.com/tc101fall2015/2015/wsq10-lists-10/ Fri, 23 Oct 2015 15:27:00 +0000 http://kenscourses.com/tc101fall2015/?guid=cebd8a88a0101340962bd3846366cb2c https://pololarinette.wordpress.com/2015/10/15/wsq10-lists/ because i had some issues understanding the formula of the standart deviation so what i did was o import a library that already included the formula and i used it for the calculation.
If you want to see the code here is the link to Github:
https://github.com/Jocapear/TC1014/blob/master/WSQ10.py]]>
This is the program working. I took some code from Paul´s blog https://pololarinette.wordpress.com/2015/10/15/wsq10-lists/ because i had some issues understanding the formula of the standart deviation so what i did was o import a library that already included the formula and i used it for the calculation.

If you want to see the code here is the link to Github:
https://github.com/Jocapear/TC1014/blob/master/WSQ10.py

]]>
https://creativecommons.org/licenses/by/4.0/
Lists! https://kenscourses.com/tc101fall2015/2015/lists/ Wed, 21 Oct 2015 15:40:09 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=133 Continue Reading →]]> For this weekly WSQ which is #10 We will be using  arrays in order to create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

So the code will look like this:

#include <iostream>
#include <math.h>
using namespace std;

float aver(float x){
  return (x/10);
}

int main (){
	float array1[10];
	float suma=0;
	float square=0, deviation;
	for (int i=0; i<10; i++)
	{
		cout<<"Please introduce the value number "<<(i+1)<<" : ";
		cin>>array1[i];
	}

	for (int i=0; i<10; i++)
	{
	suma+=array1[i];
	square+=(array1[i])*(array1[i]);
	}
	deviation=sqrt(square/10);

  cout<<""<<endl;
	cout<<"The addition is equals to: "<<suma<<endl;
	cout<<"The average of the numbers you introduce is: "<<aver(suma)<<endl;
	cout<<"The standard deviation of the numbers you introduce is: "<<deviation<<endl;

return 0;
}

And the execution will be as the following:
Lists execution

Once more, thank you for your attention and as always I will be leaving the codes on my GitHub account.

Remember to keep practicing!

-The Admin

]]>
https://creativecommons.org/licenses/by/4.0/
Lists! https://kenscourses.com/tc101fall2015/2015/lists-2/ Wed, 21 Oct 2015 15:40:09 +0000 https://myfreakingcrazythoughts.wordpress.com/?p=133 Continue Reading →]]> For this weekly WSQ which is #10 We will be using  arrays in order to create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

So the code will look like this:

#include <iostream>
#include <math.h>
using namespace std;

float aver(float x){
  return (x/10);
}

int main (){
	float array1[10];
	float suma=0;
	float square=0, deviation;
	for (int i=0; i<10; i++)
	{
		cout<<"Please introduce the value number "<<(i+1)<<" : ";
		cin>>array1[i];
	}

	for (int i=0; i<10; i++)
	{
	suma+=array1[i];
	square+=(array1[i])*(array1[i]);
	}
	deviation=sqrt(square/10);

  cout<<""<<endl;
	cout<<"The addition is equals to: "<<suma<<endl;
	cout<<"The average of the numbers you introduce is: "<<aver(suma)<<endl;
	cout<<"The standard deviation of the numbers you introduce is: "<<deviation<<endl;

return 0;
}

And the execution will be as the following:
Lists execution

Once more, thank you for your attention and as always I will be leaving the codes on my GitHub account.

Remember to keep practicing!

-The Admin

]]>
https://creativecommons.org/licenses/by/4.0/
Roll the DIEZI read the book and looked at some websites to… https://kenscourses.com/tc101fall2015/2015/roll-the-diezi-read-the-book-and-looked-at-some-websites-to/ Wed, 21 Oct 2015 00:36:00 +0000 http://opezaimd.tumblr.com/post/131587844440

Roll the DIEZ

I read the book and looked at some websites to complete my understanding about vectors and arrays.

Websites:

 http://www.cplusplus.com/reference/list/list/

https://www.programarya.com/Cursos/C++/Estructuras-de-Datos/Arreglos-o-Vectores

Code

]]>

Roll the DIEZ

I read the book and looked at some websites to complete my understanding about vectors and arrays.

Websites:

 http://www.cplusplus.com/reference/list/list/

https://www.programarya.com/Cursos/C++/Estructuras-de-Datos/Arreglos-o-Vectores

Code

]]>
https://creativecommons.org/licenses/by/4.0/