Course Review

--Originally published at Program

Welp, in summary this course was strange. I have never encountered this method of teaching in all of my years of being a student. The course is really up to each student on how they wanna take it. The material is all there, right off the bat, and you just have to make sure you meet all the requirements by the end. Exams aren’t really relevant until the end. AND you grade yourself. For me personally this was my favorite class out of all the others, the one that made me the least anxious and the one I learned the most out of. Ken was always there to help us if we needed any help, but he encouraged us to seek help from the other students. I loved it.


WSQ 13 cars

--Originally published at Program

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.

You can find the data set at the following link from the Journal of Statistics Education.

photo credit:

https://www.pexels.com/photo/road-tarmac-mountains-car-57645/


Mastery Topics (21,22)

--Originally published at Program

  1. Creation and use of ranges in Python: In a nutshell, it generates a list of numbers, which is generally used to iterate over with for loops. There’s many use cases. Often you will want to use this when you want to perform an action X number of times, where you may or may not care about the index. Other times you may want to iterate over a list (or another iterable object), while being able to have the index available
  2. Creation and use of dictionaries in Python: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’.

credit:

http://pythoncentral.io/pythons-range-function-explained/

https://notaprogrammingblog.wordpress.com/2017/05/04/_creatingandusingdictionaries/


Mastery Topics (19,20)

--Originally published at Program

  1. Validated user input (ensure correct/expected data entry): Give the user selected answers so they can’t just enter what they please.
    while userInput not in ['yes', 'no']:
  2. Reading and writing of text files: When you’re working with Python, you don’t need to import a library in order to read and write files. It’s handled natively in the language, albeit in a unique manner. The first thing you’ll need to do is use Python’s built-in open function to get a file object. The open function opens a file. It’s simple. When you use the open function, it returns something called a file object. File objects contain methods and attributes that can be used to collect information about the file you opened. They can also be used to manipulate said file. For example, the mode attribute of a file object tells you which mode a file was opened in. And the name attribute tells you the name of the file that the file object has opened. You must understand that a file and file object are two wholly separate – yet related – things.

credit:

http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python


Mastery Topics(17,18)

--Originally published at Program

  1. Creation and use of Lists/Tuples in Python:The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that items in a list need not be of the same type.

    Creating a list is as simple as putting different comma-separated values between square brackets. For example −

    list1 = ['physics', 'chemistry', 1997, 2000];
    list2 = [1, 2, 3, 4, 5 ];
    list3 = ["a", "b", "c", "d"]
  2. Creation and use of strings:Strings are amongst the most popular types in Python. We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes. Creating strings is as simple as assigning a value to a variable. For example −
    var1 = 'Hello World!'
    var2 = "Python Programming" 

credit:

https://www.tutorialspoint.com/python/python_strings.htm


Mastery Topics (15,16)

--Originally published at Program

  1. Use of recursion for repetitive algorithms: Recursion is a way of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call. If a function definition fulfils the condition of recursion, we call this function a recursive function.
    def factorial(n):
        if n == 1:
            return 1
        else:
            return n * factorial(n-1)
    
  2. When to use what type of repetition in a program: When you find that you will use a certain piece of code over and over again you can consider just writing it down in a function form and you just call upon it when need it instead of writing it all over agian.

credit:

http://www.python-course.eu/recursive_functions.php


Mastery Topics (13,14)

--Originally published at Program

  1. Use of loops with “while”:A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true.
    count = 0
    while (count < 9):
       print 'The count is:', count
       count = count + 1
    
    print "Good bye!"
  2. Use of loops with “for”: It has the ability to iterate over the items of any sequence, such as a list or a string. In a list [1,2,3] for every item add 2, result [3,4,5].
    for letter in 'Python':     # First Example
       print 'Current Letter :', letter
    
    fruits = ['banana', 'apple',  'mango']
    for fruit in fruits:        # Second Example
       print 'Current fruit :', fruit
    
    print "Good bye!"
    result.
  3. Current Letter : P
    Current Letter : y
    Current Letter : t
    Current Letter : h
    Current Letter : o
    Current Letter : n
    Current fruit : banana
    Current fruit : apple
    Current fruit : mango
    Good bye!

credit:

https://www.tutorialspoint.com/python/python_for_loop.htm


Mastery Topics (11,12)

--Originally published at Program

  1. Use of “else” with a conditional (and elif for Python):The elif statement allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.

    Similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if.

  2. Nesting of conditional statements: Those statements happen when you have an if (or another type) inside another. eg.
    if expression1:
       statement(s)
       if expression2:
          statement(s)
       elif expression3:
          statement(s)
       else:
          statement(s)
    elif expression4:
       statement(s)
    else:
       statement(s)

for more info:

https://www.tutorialspoint.com/python/nested_if_statements_in_python.htm

https://www.tutorialspoint.com/python/python_if_else.htm


Mastery Topics (9,10)

--Originally published at Program

  1. Creating and using your own modules/libraries: Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.Bdesignates a submodule named B in a package named A. Just like the use of modules saves the authors of different modules from having to worry about each other’s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or the Python Imaging Library from having to worry about each other’s module names.
    sound/                          Top-level package
          __init__.py               Initialize the sound package
          formats/                  Subpackage for file format conversions
                  __init__.py
                  wavread.py
                  wavwrite.py
                  aiffread.py
                  aiffwrite.py
                  auread.py
                  auwrite.py
                  ...
          effects/                  Subpackage for sound effects
                  __init__.py
                  echo.py
                  surround.py
                  reverse.py
                  ...
          filters/                  Subpackage for filters
                  __init__.py
                  equalizer.py
                  vocoder.py
                  karaoke.py
  2. Use of the conditional “if”:An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.

    The else statement is an optional statement and there could be at most only one else statement following if .

credit:

https://www.tutorialspoint.com/python/python_if_else.htm


Mastery Topics (7,8)

--Originally published at Program

  1. Creating functions: In the context of programming, a function is a named sequence of statements that performs a computation. When you define a function, you specify the name and the sequence of statements. Later, you can “call” the function by name. We have already seen one example of a function call: >>> type(32) <type ‘int’=””> The name of the function is type. The expression in parentheses is called the argument of the function. The result, for this function, is the type of the argument. It is common to say that a function “takes” an argument and “returns” a result. The result is called the return value.
  2. Importing and using modules/libraries: This are pre-made code that is inaccesible to python programmers unless called upon. e.g. from math import sqrt

here you can get all libraries accesible to you: https://docs.python.org/2/library/