_CourseReview

Flipped Classroom

The course was different to any course that I have had before, it consisted in having all the material available and a professor there to guide you. The time inside the classroom was merely dedicated to actively programming and asking questions about programming issues to your classmates or the teacher.

 

My experience

I really liked the methodology of the course. I believe every person is a different world with different perspectives and they learn in different ways as well, this method allows you to learn at your own pace giving you the responsability on what you want to learn and most important giving you the possibility to schedule yourself in order to achieve all your goals.

Having the posibility of learning on your own was incredible, because some of us learn in a way and solve the program with some functions but others research different stuff and solved the same problem in a different way.

This methodology was helpful for me and I really liked to go at my own pace, it made me more responsible and I really liked to help my classmates with what I learnt. This methodology is helpful for some of us, but we have to be honest that is difficult when you’re used to be told what to do, but even though I think is important to keep this methodology because it takes you out of your comfort zone and improve some soft skills that in a normal course you wouldn’t be able to.

 

 

 

_CreatingAndUsingDictionaries

A dictionary is a type of data that contains a lot of information (without order) and unique tags (keys) for every piece of information, this allows you to store information and access to that information easily.

Example of how to define a dictionary:

dictionary1 = {‘car_1’ : ‘black’, ‘car_2’ : ‘white’, ‘car_3’ : ‘red}

If you want to know the color of the car_1, you just have to write dictionary1[car_1] and it will return ‘black’.

Here’s a tutorial that explains better how to do it.

_CreatingAndUsingModules/Libraries

A library or module is a file that contains functions that you’ve already defined.

To create a library you just have to have a file in which you store all your functions.

To use it, you just have to call the function with import, this will work only if the two files are in the same folder.

Here’s a tutorial that explains better how to do it.

_ValidatedUserInput

As programmers we have to prevent all the possible scenarios that can happen while the user is running the program, sometimes we could ask for something but the user give another value that can also be accepted by the program. So, we have to create fail-safes in order to prevent that the program runs as desire.

In this example where asking the user to introduce a non-negative integer and the while loop will repeat till it gets a integer above zero.


while True:
x = int(input("Please enter a non-negative integer:"))
if x > 0:
break
print(x)

view raw

validatedinput

hosted with ❤ by GitHub

_NotExam


#Problem1
import math
def dist(x1, y1, x2, y2):
x = x2-x1
y = y2-y1
z = (x**2) + (y**2)
ans= math.sqrt(z)
return ans
#MainProgramBelow
x1 = float(input("Write the x value for the first coordinate"))
y1 = float(input("Write the y value for the first coordinate"))
x2 = float(input("Write the x value for the second coordinate"))
y2 = float(input("Write the y value for the second coordinate"))
print("The distance in between the two coordinates is:", dist(x1, y1, x2, y2))

view raw

exam1

hosted with ❤ by GitHub

 


#Problem2
def triangle(x):
for i in range(1, x+1):
z = "T" * i
print (z)
for i in range(1, x):
x -= 1
z = "T" * x
print (z)
#MainProgramBelow
x= int(input("Write the highest value of your triangle"))
triangle(x)

view raw

exam2

hosted with ❤ by GitHub

 


#Problem3
def factorial():
n = int(input("Please enter a non-negative integer:"))
counter = 0
result = 1
while counter <= n-1:
counter = counter + 1
result = result * counter
else:
print ("The factorial of the number you provide is", result)
#MainProgramBelow
while True:
factorial()
print("Y = Yes"); print("N = No")
again= input("Would you like to continue?")
if again == 'n':
print("Have a nice day")
break

view raw

exam3

hosted with ❤ by GitHub

 


#Problem4
def promedio(list):
answer = 0
for i in list:
answer = answer + i
return answer/values
#MainProgramBelow
list = []
values= int(input("How many values you want in the list:"))
for i in range(values):
num = float(input("Write a value: "))
list.append(num)
print("The average of the numbers in the list is", promedio(list))

view raw

exam4

hosted with ❤ by GitHub

 


#Problem5
def smallest_of_four(list):
small = min(list)
return small
#Main program below
w=float(input("Write the first number"))
x=float(input("Write the second number"))
y=float(input("Write the third number"))
z=float(input("Write the fourth number"))
list=[w, x, y, z]
print("The average of the numbers in the list is", smallest_of_four(list))

view raw

exam5

hosted with ❤ by GitHub

 


#Problem6
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
#MainProgramBelow
n=int(input("Write the number you want to know the fibonacci number of:"))
print("The fibonacci value of", n ,"is:", fib(n))

view raw

exam6

hosted with ❤ by GitHub

 


#Problem7
def sumsquares_list(list):
sum_squares = 0
for i in list:
x = i **2
sum_squares += x
return sum_squares
#Main program below
list = []
values= int(input("How many values you want in the list:"))
for i in range(values):
num = int(input("Write a value:"))
list.append(num)
print ("The sum of the squares of the list you provided is", sumsquares_list(list))

view raw

exam7

hosted with ❤ by GitHub

 


#Program8
def sqrt(x, eps=1e-6):
r = x * 1
while abs(x – r * r) > eps:
r = 0.5 * (r + x / r)
return r
#Main program below
w=float(input("Write the number:"))
print("The babilonian square root of the number you provided is", sqrt(w))

view raw

exam8

hosted with ❤ by GitHub

 


#Problem9
import string
def find_bananas(file_name):
f = open(file_name,'r')
counter = 0
for line in f:
line = line.lower()
index = line.find("banana")
while index > -1:
counter +=1
index = line.find("banana",index+1)
return counter
#MainProgramBelow
print("The number of bananas in your file is", find_bananas("bananas.txt"))

view raw

exam9

hosted with ❤ by GitHub

 


#Problem10
def gcd(x, y):
reminder = 0
while y > 0:
reminder = y
y = x % y
x = reminder
return x
#Main program below
num1=int(input("Write the first number"))
num2=int(input("Write the first number"))
print ("The greatest common divisor of", num1, "and", num2, "is", gcd(num1, num2))

view raw

exam10

hosted with ❤ by GitHub

#WSQ13

Task

File input/output is our access to permanent stores of data that last beyond the run time of our application.

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.


import urllib.request
def average(lst1, index):
funclst = []
for car in lst2:
templst = car.split()
funclst.append(templst[index])
funclst = list(map(float,funclst))
av = sum(funclst)/len(funclst)
return av
def main():
url = 'https://ww2.amstat.org/publications/jse/datasets/93cars.dat.txt&#39;
response = urllib.request.urlopen(url)
data = response.read()
txt = data.decode('utf-8')
lst = txt.split()
lst2 = []
i,j = (0,0)
while i < len(lst):
if i%26 == 0:
lst2.append(lst[i])
j += 1
else:
lst2[j-1] += "" + lst[i]
i += 1
print("The average gas mileage in city is:", average(lst2,6))
print("The average gas mileage in highwat is:", average(lst2,7))
print("The average midrange price of the vehicles in the set:", average(lst2,4))
if __name__=="__main__":
main()

view raw

WSQ13

hosted with ❤ by GitHub

 

#WSQ12

Task

In this assignment you will estimate the mathematical constant e. You should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

You will want to use the infinite series to calculate the value, stopping when the accuracy is reached (previous and current calculation are the same at the specified accuracy).


def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x-1)
def calculate_e(precision):
e = 0
x = 0
difference = 10
for i in range (0, difference):
e = 1 / factorial(i)
x += e
x = str(x)
count = 0
while count != precision + 2:
print(x[count], end = '')
count += 1
return x
#MainProgramBelow
precision = int(input("Introduce the decimal points of accuracy you want:"))
calculate_e(precision)

view raw

WSQ12

hosted with ❤ by GitHub

https://gist.github.com/ebovio/a711226af729eb0c01c96990b98318e0

 

#WSQ11

Task

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). Create your own test file (plain text) to check your work.


import string
def find_bananas(file_name):
f = open(file_name,'r')
counter = 0
for line in f:
line = line.lower()
index = line.find("banana")
while index > -1:
counter +=1
index = line.find("banana",index+1)
return counter
#MainProgramBelow
print("The number of bananas in your file is", find_bananas("bananas.txt"))

view raw

WSQ11

hosted with ❤ by GitHub

Learnings

  • Reading text files: If you want to use external files in Python3, you can do it in many ways: read, write, append and the binary versions of the previous three. To use a file, you have to open it with the open() function, that works like this open(‘[fileaddress]’,'[opening mode]’).

 

https://www.instagram.com/p/BSeYSpVFtne/?taken-by=_ebovio

 

#WSQ10

Task

In this assignment you will write a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find.

The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.


def sqrt(x, eps=1e-6):
r = x * 1
while abs(x – r * r) > eps:
r = 0.5 * (r + x / r)
return r
#Main program below
w=float(input("Write the first number"))
print(sqrt(w))

view raw

WSQ10

hosted with ❤ by GitHub

 

View this post on Instagram

#HospicioCabañas #Architecture #Guadalajara

A post shared by Enrique Bovio (@_ebovio) on