Difference between revisions of "EGR 103/Concept List Fall 2019"

From PrattWiki
Jump to navigation Jump to search
Line 1: Line 1:
This page will be used to keep track of the commands and major concepts for each lab in [[EGR 103]].  
+
This page will be used to keep track of the commands and major concepts for each lecture in [[EGR 103]].  
 
   
 
   
== Lectures ==
+
== Lecture 1 - Introduction ==
 
 
=== Lecture 1 - Introduction===
 
 
* Class web page: [http://classes.pratt.duke.edu/EGR103S19/ EGR 103L]; assignments, contact info, readings, etc - see slides on Errata/Notes page
 
* Class web page: [http://classes.pratt.duke.edu/EGR103S19/ EGR 103L]; assignments, contact info, readings, etc - see slides on Errata/Notes page
 
* Sakai page: [https://sakai.duke.edu/portal/site/egr103s19 Sakai 103L page]; grades, surveys and tests, some assignment submissions
 
* Sakai page: [https://sakai.duke.edu/portal/site/egr103s19 Sakai 103L page]; grades, surveys and tests, some assignment submissions
 
* Piazza page: [https://piazza.com/duke/spring2019/egr103/home Piazza 103L page]; message board for questions
 
* Piazza page: [https://piazza.com/duke/spring2019/egr103/home Piazza 103L page]; message board for questions
  
=== Lecture 2 - Programs and Programming===
+
== Lecture 2 - Programs and Programming ==
 
* To play with Python:
 
* To play with Python:
 
** Install it on your machine or a public machine: [https://www.anaconda.com/download/ Download]
 
** Install it on your machine or a public machine: [https://www.anaconda.com/download/ Download]
Line 21: Line 19:
 
* Some commands are only available by importing from modules; <code>import numpy as np</code> will bring in all the functions of the numpy module.  Access these commands by typing np.VALUE or np.FUNCTION (for example, np.pi or np.cos(2))
 
* Some commands are only available by importing from modules; <code>import numpy as np</code> will bring in all the functions of the numpy module.  Access these commands by typing np.VALUE or np.FUNCTION (for example, np.pi or np.cos(2))
  
=== Lecture 3 ===
+
== Lecture 3 ==
 
* Python has several different variable types, each with their own purpose and operators.
 
* Python has several different variable types, each with their own purpose and operators.
 
* Main ones this lecture: int, float, string, tuple, list.
 
* Main ones this lecture: int, float, string, tuple, list.
  
=== Lecture 4 ===
+
== Lecture 4 ==
 
* Brief discussion of disctionaries, how to build, and how to access.
 
* Brief discussion of disctionaries, how to build, and how to access.
 
* Two main types of function - lambda functions and defined functions
 
* Two main types of function - lambda functions and defined functions
Line 33: Line 31:
 
** Four different types of inputs -  
 
** Four different types of inputs -  
  
=== Lecture 5 ===
+
== Lecture 5 ==
 
* Creating formatted strings using {} and .format() ([https://www.python.org/dev/peps/pep-3101/#format-strings format strings], [https://www.python.org/dev/peps/pep-3101/#standard-format-specifiers standard format specifiers] -- focus was on using e or f for type, minimumwidth.precision, and possibly a + in front to force printing + for positive numbers.
 
* Creating formatted strings using {} and .format() ([https://www.python.org/dev/peps/pep-3101/#format-strings format strings], [https://www.python.org/dev/peps/pep-3101/#standard-format-specifiers standard format specifiers] -- focus was on using e or f for type, minimumwidth.precision, and possibly a + in front to force printing + for positive numbers.
 
* Basics of decisions using if...elif...else
 
* Basics of decisions using if...elif...else
Line 70: Line 68:
 
</div>
 
</div>
  
=== Lecture 6 ===
+
== Lecture 6 ==
 
* The Price Is Right - Clock Game:
 
* The Price Is Right - Clock Game:
 
<div class="mw-collapsible mw-collapsed">
 
<div class="mw-collapsible mw-collapsed">

Revision as of 15:59, 7 February 2019

This page will be used to keep track of the commands and major concepts for each lecture in EGR 103.

Lecture 1 - Introduction

  • Class web page: EGR 103L; assignments, contact info, readings, etc - see slides on Errata/Notes page
  • Sakai page: Sakai 103L page; grades, surveys and tests, some assignment submissions
  • Piazza page: Piazza 103L page; message board for questions

Lecture 2 - Programs and Programming

  • To play with Python:
    • Install it on your machine or a public machine: Download
  • Quick tour of Python
    • Editing window, variable explorer, and console
    • Variable explorer is your friend
  • From Dewey - programming language typically have ability to work with input, output, math, conditional execution, and repetition
  • Hilton and Bracy Seven Steps
  • Class work developing algorithm for program to determine if a number is prime
  • Inputs in Python using input() command - always grab strings
  • Convert strings containing integer characters to integers using int()
  • Some commands are only available by importing from modules; import numpy as np will bring in all the functions of the numpy module. Access these commands by typing np.VALUE or np.FUNCTION (for example, np.pi or np.cos(2))

Lecture 3

  • Python has several different variable types, each with their own purpose and operators.
  • Main ones this lecture: int, float, string, tuple, list.

Lecture 4

  • Brief discussion of disctionaries, how to build, and how to access.
  • Two main types of function - lambda functions and defined functions
  • Lambda functions are one line of code; can have multiple inputs but only one expression.
    • c = lambda a,b: np.sqrt(a**2 + b**2)
  • Defined functions can be multiple lines of code and have multiple outputs.
    • Four different types of inputs -

Lecture 5

  • Creating formatted strings using {} and .format() (format strings, standard format specifiers -- focus was on using e or f for type, minimumwidth.precision, and possibly a + in front to force printing + for positive numbers.
  • Basics of decisions using if...elif...else
  • Basics of loops using for and while
  • Building a program to count the number of numbers, vowels, consonants, and other characters in a phrase
# letter_counter.py from class:
def counter(phrase):
    counts = [0, 0, 0, 0]
    nums = "0123456789"
    vowels = "aeiou"
    cons = "bcdfghjklmnpqrstvwxyz"

    for k in phrase.lower():
        #print(k)
        if k in nums:
            # print('{:s} is a number!'.format(k))
            counts[0] += 1
        elif k in vowels:
            counts[1] += 1
        elif k in cons:
            counts[2] += 1
        else:
            counts[3] += 1
               
    return counts
        
c = counter("Hello! Go 2022! East Campus Rocks!")
print(c)

Lecture 6

  • The Price Is Right - Clock Game:
# tpir.py from class:
# -*- coding: utf-8 -*-
"""
The Price Is Right - Clock Game
"""

import numpy as np
import time

def create_price(low, high):
    return np.random.randint(low, high+1)

def get_guess():
    guess = int(input('Guess: '))
    return guess

def check_guess(new_guess, price):
    if new_guess  > price:
        print('${:0.0f} is too high - Lower!'.format(new_guess))
    elif new_guess < price:
        print('Higher!')
    else:
        print('You win!')


price = create_price(100, 1000)
# print(price)
new_guess = price + 1
start_time = time.clock()

while new_guess != price and (time.clock()-start_time)<30:
    new_guess = get_guess()
    # print(new_guess)
    check_guess(new_guess, price)
    
if new_guess != price:
    print('You lose :( '))

Lecture 7

  • Robust programming
  • isinstance to check type

div class="mw-collapsible mw-collapsed">

  • # validator.py from class:
    
def check_for_int(x):
    '''
    returns true if string contains an valid int
    returns false otherwise
    '''
    for k in x:
        if k not in '0123456789':
            return False

    return True


def get_good():
    x = input('Integer between 0 and 10: ')
    bad = True
    ''' not quite
    while bad:
        if check_for_int(x) is False:
            pass
        elif int(x)>=0 and int(x)<=10:
            bad = False
    return int(x)
    '''
    while bad:
        if check_for_int(x) is False:
            print('Wrong type of input')
            x = input('INTEGER between 0 and 10: ')
        elif int(x) < 0 or int(x) > 10:
            print('Invalid value')
            x = input('Integer BETWEEN 0 and 10: ')
        else:
            bad = False

    return int(x)


if __name__ == "__main__":
    check_for_int('1.1')
    y = get_good()
    print(y)
  • Note: my_string.isdigit() works like check_for_int() above

Lecture 8

  • Taylor series fundamentals
  • Maclaurin series approximation for exponential
  • Newton Method for finding square roots
  • See Python version of Fig. 4.2 and modified version of 4.2 in the Resources section of Sakai page under Chapra Pythonified