WSQ 13 – Cars

--Originally published at Programming

Instructions: Write a program that opens and reads the file 93cars.dat.txt and produces the following data:

  • average gas mileage in city (City MPG)
  • average gas mileage on highway (Highway MPG)
  • average midrange price of the vehicles in the set.

Data from: Journal of Statistics Education.

Code:

Captura de pantalla 2017-05-04 a la(s) 15.49.08

Data:

Captura de pantalla 2017-05-04 a la(s) 15.53.16.png

How it runs:

Captura de pantalla 2017-05-04 a la(s) 15.48.57

 

Mastery topics: Reading and writing of text files


course review, x out of y?

--Originally published at Tomas Enciso

Not too sure where to start. Just like the course its not like you can give a rating like a five star or x out of 10. Personally I think it’s a new and great way to learn, this gives the student total control on the assignments, mainly when to do them and how, that is a good thing and a bad thing, just look at me, it’s 7 am and I’m trying to finish blog posts 3 hours before the final exam that I started several weeks ago and for some reason I kept postponing these assignments, in a weird way this is also very good, this of course is not that laboral world but we get a glimpse of it, outside the teacher won’t be behind us like in school. The responsibility is on us to finish what we have to finish. Maybe I’m not used to this for several reasons (maybe I’ll blog about that someday). I think this course gives a lot of freedom but it’s not like you have to figure everything out, ken is actually there when ever you need him, just look at his booking system or his social media. Overall this course is great for those who get stuff done and for us are not quite there yet it’s also great because now I know what I really need to improve plus this course is still open after it’s over thanks to the many blogposts. I know this post might not make a lot of sense but hey it’s 7:33 am and I’m about to do the final exam. I give this class a x out of y because you know every student makes whatever they want out of it (just in case you didn’t get it).


Mastery topics part 1

--Originally published at Tomas Enciso

-use of comments

-basic types and their use

-basic output (print)

-calling functions

-creating functions

-importing and using modules/libraries

-use of the conditional “if”

-use of “else” with a conditional (and elif for Python

-Nesting of conditional statements

-use of loops with “while”

-use of loops with “for”

-creation and use of lists in Python

-validated user input

-creation and use of ranges in Python


Wsq03

--Originally published at Tomas Enciso

This program allows the computer to pick a random number between 1 and 100 hundred, the user then has to guess that number and the program will tell if its too high or too low and at the end tell how many times that person guessed.

Screen Shot 2017-05-04 at 6.14.21 AM.pngScreen Shot 2017-05-04 at 6.15.52 AM

there I started with 50 and as the program was telling me I tried to guess the number which in the end was 77 and I guessed 5 times to get it right.


Quiz 11 – part II

--Originally published at Programming

Hello! This is the second part of this quiz because the first time I made this blog I skip some exercises. One of them was on the real exam (yes, so sad). Well, I just going to talk about the last problem (number 10), because number 8 (Babylonian method) and 9 (Go Bananas) are in Quiz 14 – Exam.

Instructions: Write a function called gcd that receives to positive integers and returns the greatest  common divisor of them (the largest integer that divides both of the parameters evenly).

Code:

Captura de pantalla 2017-04-27 a la(s) 13.31.03

How it runs:

Captura de pantalla 2017-04-27 a la(s) 13.30.52

 

Hope it helps ?


Quiz 14 – Exam

--Originally published at Programming

Hello everybody.

Today we have questions to practice for the exam. It’s similar to my blog quiz 11, but now complete.

Exercises

We have already done the first part:

1.- See question 2 from Quiz 11 ?

2.- See question 4 from Quiz 11 ?

3.- See question 5 from Quiz 11 ?

4.- Go to Quiz 08 ?

This is new:

5.- Babylonian method

This is like WSQ10, but we can review it again here.

Instructions: Write a function to calculate the square root of a number x using the Babylonian method, it receives a single parameter: the number x and returns the value of the square root of x when two successive estimates differ only by 0.0001 (or less).

Code:

Captura de pantalla 2017-04-27 a la(s) 13.43.32

It runs like:

Captura de pantalla 2017-04-27 a la(s) 13.43.59

 

6.- Bananas

This is like WSQ11, but we can review it again here.

Instructions: Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana” is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.

Code:

Captura de pantalla 2017-04-27 a la(s) 13.17.14

How it runs:

Captura de pantalla 2017-04-27 a la(s) 13.18.15

 

 

 


WSQ 11 – Go Bananas

--Originally published at Programming

Hello everyone

For this week assigment we have to: Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana”  (or “BANANA” ) is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two).

Here is the code:

Captura de pantalla 2017-04-27 a la(s) 13.17.14

And this is how it runs:

Captura de pantalla 2017-04-27 a la(s) 13.18.15


WSQ10 – Babylonian Method

--Originally published at Programming

Hello!

This week we have this instructions: In this assignment you will write a function to calculate the square root of a number using the Babylonian method. The function should receive a number and return floating point number.

First of all, we should know what the Babylonian method is. I could recommend visit Wikipedia or this video too: Solving Square Roots: Babylonian Method

Ok, now…

Here is the code:

Captura de pantalla 2017-04-27 a la(s) 13.43.32

And it runs like this:

Captura de pantalla 2017-04-27 a la(s) 13.43.59

Hope it helps ?


Quiz 11

--Originally published at Programming

Hello, today we have some practice for the exam in this quiz. It’s about problems to solve.

1.- It is like quiz 09, clic to review.

2.- Instructions: Escribe un función que se llama triangulo cual recibe un parámetro size y imprime un triangulo derecho como el siguiente. El renglón mas grande debe llevar size numero de “T”. SOLO imprime los “T”s y los endlines. Nota que no hay characteres (espacios) a la derecha de los T’s. Debe usar un ciclo “for” para controlar el repetición.

Code:
Captura de pantalla 2017-04-26 a la(s) 09.19.43
It runs like this:
Captura de pantalla 2017-04-26 a la(s) 09.19.35
3.-  It also he have already seen, in blog wsq06.
4.- Instructions: Escribe una función que se llama promedio_lista que recibe un parámetro (una lista (Py thon) o arreglo/Vector de C++) de valores float y regresa como float el promedio de los números en la lista.
Code:
Captura de pantalla 2017-04-26 a la(s) 09.25.15
How it runs:
Captura de pantalla 2017-04-26 a la(s) 09.27.06
5.- This we have seen too in an other blog, but let’s review here by the way.
Instructions: Escribe una función que se llama promedio_lista que recibe un parámetro (una lista (Python) de valores float y regresa como float el promedio de los números en la lista.
Code:
Captura de pantalla 2017-04-26 a la(s) 09.28.09Captura de pantalla 2017-04-26 a la(s) 09.28.39
6.- This problem is in blog Quiz 8.
7.- And finally, we have this:
Instructions: Escribe una función que se llama sumsquares_list cual recibe una lista (list en Python) de números y regresa la suma de los números cuadrados.
 Captura de pantalla 2017-04-26 a la(s) 09.33.03
Captura de pantalla 2017-04-26 a la(s) 09.33.56

Factorial Calculator – WSQ06

--Originally published at Programming

Hello! Today we are doing a factorial calculator. This is about calculate the factorial of a number, asking the user for a non-negative integer. If you don’t know is the factorial or you want to refresh, you can know about it in Wikipedia-Factorial.

Well, as usual, here is the code: (and then I will explain)

Captura de pantalla 2017-03-20 a la(s) 08.26.41

First we print an introduction phrase for the user. The objetive of this exercise is to use loops. To start the loop our coindition needs to be true, thats why we declared repeat as “yes” and the we start the loop.

Inside this loop, we ask for the number like an int. Then we inicialize the counter like one and the fact too, fact is the number that will be multipliying and incrementing. For that happens we made another loop. The condition as we see is that the counter is different than the number (that the user give us) plus one. This way then we see that fact will be multiplicating the counter and after that it will increase one.

After this math operations we print the result with a sentence to advise, and finally we ask the user if he want to repeat the cycle.

If yes, all start again. If no, we just print Thanks.

And that’s it. This is how it runs:

Captura de pantalla 2017-03-20 a la(s) 08.27.14

Hope it helps ?