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
fersabal’s Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 05:59:33 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Cars https://kenscourses.com/tc101fall2015/2015/cars-4/ Thu, 26 Nov 2015 05:59:33 +0000 http://saldabal.wordpress.com/?p=198 Continue Reading →]]> #Jorge Fernando Saldaña Cabal
#A01350730

archivo = open(“carros.txt”, “r”)
lineas = archivo.readlines()
#def primero:
y = 0
contcity = 0

for i in lineas:
x = (i[52:54])
if (x != “”):
x = float(x)
y = y + x
contcity = contcity + 1
city = y//contcity
print(‘The average gas mileage in city is: ‘,city)
p = 0
conthigh = 0
for i in lineas:
z = (i[55:57])
if (z != “”):
z = float(z)
p = p + z
conthigh = conthigh + 1
high = p // conthigh
print(‘The average gas mileage in highway is: ‘,high)

f = 0
contmind = 0
for i in lineas:
a = (i[42:46])
if (a != “”):
a = float(a)
f = f + a
contmind = contmind + 1
mind = y//contmind
print(‘The average mind-range price is: ‘,mind)

#52

]]>
https://creativecommons.org/licenses/by/4.0/
Open and read files https://kenscourses.com/tc101fall2015/2015/open-and-read-files/ Thu, 26 Nov 2015 05:46:48 +0000 http://saldabal.wordpress.com/?p=192 Continue Reading →]]> This was a very challegnig thing i’ve got to get through in  the semester.

To learn how to open and read files i had to read a lot of times the same thing of the “How to think like a computer scientist”

There are special words to do this how ever the esscentials does not need you to import any module which is good for us.

First of all we have to tell python we want to open a file, to do this we must type set a variable and set the open to it like this:

variable = open(“name of the file.txt”, “r”)

It is very important that we put our paraeters in this case within quot marks, as you see up you have to type an ‘r’ after the name of the text which indicates that is reading.

Now we have it open we have to read it.

To read the text we can choose between read line by line orto read all of them.

1 line at a time: variable = previous_variable.readline()

all of them: variable = previous_variable.readlines()

From here you just haveto get creative and do the stuff you want. And just dont remember that always at the end you must close your text with:

variable.close

An example:

archivo = open(‘bananas.txt’, ‘r’)

one = archivo.readline()

print (one)

close.archivo

 

Hope you enjoy it!

 

 

 

]]>
https://creativecommons.org/licenses/by/4.0/
BONUS POINTS https://kenscourses.com/tc101fall2015/2015/bonus-points-7/ Thu, 26 Nov 2015 05:34:29 +0000 http://saldabal.wordpress.com/?p=186 In the next video i give future students some tips on how to succed on Kens class. Enjoy it!

]]>
https://creativecommons.org/licenses/by/4.0/
Sent work via Github https://kenscourses.com/tc101fall2015/2015/sent-work-via-github/ Thu, 26 Nov 2015 05:29:49 +0000 http://saldabal.wordpress.com/?p=182 In the following video i show you how to use the basics of Github and how you can send your work so other people can see your code.

]]>
https://creativecommons.org/licenses/by/4.0/
Show you i installed linux https://kenscourses.com/tc101fall2015/2015/show-you-i-installed-linux/ Thu, 26 Nov 2015 05:23:31 +0000 http://saldabal.wordpress.com/?p=178 The following video will show youi have installed linux in my personal computer:

]]>
https://creativecommons.org/licenses/by/4.0/
Estimating e https://kenscourses.com/tc101fall2015/2015/estimating-e-5/ Thu, 26 Nov 2015 05:16:17 +0000 http://saldabal.wordpress.com/?p=170 Continue Reading →]]> This task was not that hard. We had to make a function that computes an estimation of e, which is a number very used in finances. The trick was our number must have the accuracy given by the user.

Here is my code:

https://github.com/sabaldaba/TC101/blob/master/Estimating_e

]]>
https://creativecommons.org/licenses/by/4.0/
Yo soy 196 https://kenscourses.com/tc101fall2015/2015/yo-soy-196-8/ Thu, 26 Nov 2015 05:10:46 +0000 http://saldabal.wordpress.com/?p=165 Continue Reading →]]> This task was of the most challenging ones of the entire course. We had to make a programm to find candidates of lychrel numbers in a given range. First of all i had to look what a lychrel number was because i never heard of it. Then i found out that theres a theory that when you add a number to its inverse ‘n’ times eventually it will become palyndrome which means, if you read it backward it would be the same as if you read it normally.

But there are some numbers that havent been able to prove this theory, i even read that ones, scientifics let a computer programm running for three years in search for its palyndrome, eventually they stopped the programm and found a number of one million digits which is a lot, but never the palyndrome.

I get confused a lot with variables but at the end Ken helped me to fix the last problems, here is my code: https://github.com/sabaldaba/TC101/blob/master/wsq11_soy:196

 

Hope you like it!

]]>
https://creativecommons.org/licenses/by/4.0/
Recursion for repetitive algorithms https://kenscourses.com/tc101fall2015/2015/recursion-for-repetitive-algorithms-2/ Wed, 25 Nov 2015 13:10:10 +0000 http://saldabal.wordpress.com/?p=151 Continue Reading →]]> Sometimes we will be coding a fucntion that need to be more than one time. So we will be facing a problem since mayve we would be able to solve our problem by making our algorithm longer but at the end thats not how we should learn to program. We should learn how to be efficient and fast, so we must learn what recursion means which is just what we need in cases like this.

A recursion allow a function to be written inside itself so it can run more than one time. The function would be running itself.

A lot of information about recursion states that knowing how to create a program that gets you the factorial number is an awesome begining to understand recursion.

The code would be like this.

def factorial(a):

if a == 1:

return 1

return (a*factorial(a-1))

We can see how at the last line the programm compute the function inside the function. The programm would do something like

5! = 4 * 3 * 2 * 1

and this will make it faster and more efficient

]]>
https://creativecommons.org/licenses/by/4.0/
Nesting conditionals https://kenscourses.com/tc101fall2015/2015/nesting-conditionals/ Wed, 25 Nov 2015 12:47:57 +0000 http://saldabal.wordpress.com/?p=137 Continue Reading →]]> So far we’ve seen how to use loops, while and for loops. And we’ve learned that they are very useful in almost any program we want to do. But there will be a time when our programms become complex when we will want to evualte a condition if another turn out to be true, an example:

if variable < 200:

if variable == 150:

do something

elif variable == 100:

do something

else:

do something

else variable > 200:

do something

 

We can see how in here we evalate if our variable was in range below 200 and then if it had exactly the value of 150 and then of 100, if non of there were true we also state something.

This is what nested conditionals work for.

 

 

 

 

 

 

]]>
https://creativecommons.org/licenses/by/4.0/
Quiz11 https://kenscourses.com/tc101fall2015/2015/quiz11-14/ Sun, 22 Nov 2015 05:48:46 +0000 http://saldabal.wordpress.com/?p=127 Continue Reading →]]> For this quiz we had to make two programms. One that calculate the value o e with the given accuracy by the user and a program that search for the word banana in a text file.

I struggled with the file question since i dont know how to use properly the .split() very well but still i did my best effort.

Here is my code of the first question: https://github.com/sabaldaba/TC101/blob/master/Question1-quiz

And the second one: https://github.com/sabaldaba/TC101/blob/master/question2-quiz11

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