Difference between revisions of "EGR 103/Concept List/F21"

From PrattWiki
Jump to navigation Jump to search
(Lecture 1)
Line 25: Line 25:
 
** <code>VAR = input("prompt: ")</code> will ask the user for a value and stores whatever they type as a string
 
** <code>VAR = input("prompt: ")</code> will ask the user for a value and stores whatever they type as a string
 
** <code>NUM = int(VAR)</code> will convert the item in VAR to an integer if it looks like an integer; error otherwise
 
** <code>NUM = int(VAR)</code> will convert the item in VAR to an integer if it looks like an integer; error otherwise
 +
 +
check back soon for an accurate page!
 +
 +
== Lecture 1 - Course Introduction ==
 +
* Class web page: [http://classes.pratt.duke.edu/EGR103S21/ EGR 103L]; assignments, contact info, readings, etc - see slides on Errata/Notes page
 +
* Sakai page: [https://sakai.duke.edu/portal/site/egr103s21 Sakai 103L page]; grades, surveys and tests, some assignment submissions
 +
* Pundit page: [[EGR 103]]; reference lists
 +
* CampusWire page: [https://campuswire.com/c/GCF3AD33A/feed CampusWire 103L page]; message board for questions - you need to be in the class and have the access code 0878 to subscribe.
 +
 +
== Lecture 2 - Programs and Programming ==
 +
* Almost all languages have input, output, math, conditional execution, and repetition
 +
* Seven steps of programming
 +
** Watch video on [https://www.coursera.org/lecture/duke-programming-web/developing-an-algorithm-nopgq Developing an Algorithm]
 +
** Watch video on [https://www.coursera.org/lecture/duke-programming-web/a-seven-step-approach-to-solving-programming-problems-AEy5M A Seven Step Approach to Solving Programming Problems]
 +
* Consider how to decide if a number is a prime number
 +
* To play with Python:
 +
** Install it on your machine or a public machine: [https://www.anaconda.com/download/ Download]
 +
* Quick tour of Python
 +
** Editing window, variable explorer, and console
 +
* You are not expected to remember any of the specifics about how Python stores things or works with them yet!
 +
 +
== Lecture 3 - "Number" Types ==
 +
* Finished prime number checker - code is available in the Box drive for the class under Lectures / Lec03
 +
** Looked at for loops for running code multiple times
 +
** Looked at if...else trees for making decisions
 +
** Created a variable to track whether we thought the number was prime
 +
* Python is a "typed" language - variables have types.  We will use several types:
 +
** Focus of the day: int, float, and array
 +
** Focus a little later: string, list, tuple
 +
** Focus later: dictionary, set
 +
** Focus way later: map, filter, zip
 +
* int: integers; Python 3 can store these perfectly
 +
* float: floating point numbers - "numbers with decimal points" - Python sometimes has problems storing floating point items exactly
 +
* array
 +
** Requires numpy, usually with <code>import numpy as np</code>
 +
** Organizational unit for storing rectangular arrays of numbers
 +
** Generally create with np.array(LIST) where depth of nested LIST is dimensionality of array
 +
*** np.array([1, 2, 3]) is a 1-dimensional array with 3 elements
 +
*** np.array([[1, 2, 3], [4, 5, 6]]) is a 2-dimension array with 2 rows and 3 columns
 +
* Math with "Number" types works the way you expect
 +
** ** * / // % + -
 +
** With arrays, * and / work element by element; *matrix* multiplication is a different character (specifically, @)
 +
* Relational operators can compare "Number" Types and work the way you expect with True or False as an answer
 +
** < <= == >= > !=
 +
** With arrays, either same size or one is a single value; result will be an array of True and False the same size as the array
 +
* Slices allow us to extract information from a collection or change information in mutable collections
 +
* a[0] is the element in a at the start
 +
* a[3] is the element in a three away from the start
 +
* a[-1] is the last element of a
 +
* a[-2] is the second-to-last element of a
 +
* a[:] is all the elements in a because what is really happening is:
 +
** a[start:until] where start is the first index and until is just *past* the last index;
 +
** a[3:7] will return a[3] through a[6] in a 4-element array
 +
** a[start:until:increment] will skip indices by increment instead of 1
 +
** To go backwards, a[start:until:-increment] will start at an index and then go backwards until getting at or just past until.
 +
* For 2-D arrays, you can index items with either separate row and column indices or indices separated by commas:
 +
** a[2][3] is the same as a[2, 3]
 +
** Only works for arrays!

Revision as of 16:34, 30 August 2021

Lecture 1

  • Main class page: EGR 103L.
  • See information on PDF of slide show on Errata / Notes page.
  • Sakai page: Sakai 103L page; grades, surveys and tests, some assignment submissions
  • Pundit page: EGR 103; reference lists
  • CampusWire page: CampusWire 103L page; message board for questions - you need to be in the class and have the access code 8018 to subscribe.

Lecture 2 - Programs and Programming

  • Almost all languages have input, output, math, conditional execution (decisions), and repetition (loops)
  • Seven steps of programming The Seven Steps Poster
  • Consider how to decide if a number is a prime number
  • To play with Python:
    • Install it on your machine or a public machine: Download
  • Quick tour of Python
    • Editing window, variable explorer, and console
    • Main numerical types: whole numbers (int) and numbers with decimals (float)
    • + - * // (rounded division) and % (remainder / modula) produce in if both sides are an int, float if either or both are floats
    • / (regular division) and // (rounded division) produces float with ints or floats
    • ** to do powers
    • Python doesn't know everything to start with; may need to import things
      • import MODULE means using MODULE.function() to run
      • import MODULE as NAME means using NAME.function() to run
    • VAR = input("prompt: ") will ask the user for a value and stores whatever they type as a string
    • NUM = int(VAR) will convert the item in VAR to an integer if it looks like an integer; error otherwise

check back soon for an accurate page!

Lecture 1 - Course 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
  • Pundit page: EGR 103; reference lists
  • CampusWire page: CampusWire 103L page; message board for questions - you need to be in the class and have the access code 0878 to subscribe.

Lecture 2 - Programs and Programming

  • Almost all languages have input, output, math, conditional execution, and repetition
  • Seven steps of programming
  • Consider how to decide if a number is a prime number
  • To play with Python:
    • Install it on your machine or a public machine: Download
  • Quick tour of Python
    • Editing window, variable explorer, and console
  • You are not expected to remember any of the specifics about how Python stores things or works with them yet!

Lecture 3 - "Number" Types

  • Finished prime number checker - code is available in the Box drive for the class under Lectures / Lec03
    • Looked at for loops for running code multiple times
    • Looked at if...else trees for making decisions
    • Created a variable to track whether we thought the number was prime
  • Python is a "typed" language - variables have types. We will use several types:
    • Focus of the day: int, float, and array
    • Focus a little later: string, list, tuple
    • Focus later: dictionary, set
    • Focus way later: map, filter, zip
  • int: integers; Python 3 can store these perfectly
  • float: floating point numbers - "numbers with decimal points" - Python sometimes has problems storing floating point items exactly
  • array
    • Requires numpy, usually with import numpy as np
    • Organizational unit for storing rectangular arrays of numbers
    • Generally create with np.array(LIST) where depth of nested LIST is dimensionality of array
      • np.array([1, 2, 3]) is a 1-dimensional array with 3 elements
      • np.array([[1, 2, 3], [4, 5, 6]]) is a 2-dimension array with 2 rows and 3 columns
  • Math with "Number" types works the way you expect
    • ** * / // % + -
    • With arrays, * and / work element by element; *matrix* multiplication is a different character (specifically, @)
  • Relational operators can compare "Number" Types and work the way you expect with True or False as an answer
    • < <= == >= > !=
    • With arrays, either same size or one is a single value; result will be an array of True and False the same size as the array
  • Slices allow us to extract information from a collection or change information in mutable collections
  • a[0] is the element in a at the start
  • a[3] is the element in a three away from the start
  • a[-1] is the last element of a
  • a[-2] is the second-to-last element of a
  • a[:] is all the elements in a because what is really happening is:
    • a[start:until] where start is the first index and until is just *past* the last index;
    • a[3:7] will return a[3] through a[6] in a 4-element array
    • a[start:until:increment] will skip indices by increment instead of 1
    • To go backwards, a[start:until:-increment] will start at an index and then go backwards until getting at or just past until.
  • For 2-D arrays, you can index items with either separate row and column indices or indices separated by commas:
    • a[2][3] is the same as a[2, 3]
    • Only works for arrays!