Class 3 – Monday August 31
March on even though it’s August
Together we learn — To say what we mean to say — Most valuable skill
What makes me happy — Students asking their questions — So please keep it up.
That Black Lives Matter — Should be so easy to grasp — People are people
Look both ways
Examples from last class – any questions?
What is happening today
- Continue our exploration of digital problem solving
- We will do this every class this semester
- Expand our communication and abstraction skills
- Readability and consistency
- Ideas and plans are only good if they can be easily understood.
- Must appreciate and strive for writing readable code
- Practice debugging
- Pay mindful attention to what our solutions actually say to do.
- Recognize naming allows us to interact with the world around us.
- Ability to name values is part of the essence of being human.
- Ability to name values is a cornerstone of programming. Variables will be the means to do so.
- Introduce how Python supports integer, decimal, and string values, and their manipulation.
- Introduce additional terminology to which you should become accustomed
Examples of the day – please download now
- Introduces the importance of guidelines and standard practices. One popular such example is the Google Python Style Guide.
- Program contains several errors that need to be fixed.
- Introduces the
int
numeric type.
- Also, introduces some additional built-in functions.
- Introduces the
float
numeric type.
- Introduces the mixed mode numeric type.
- Also introduces the
.
operator. The operator is typically called the dot or selection operator. The.
tells Python that an element of the resource to its left is having one of its components (the one to its right) being selected for use.`
- Introduces the string concatenation operator
+
and replication operator*
.
### operator + performs concatenation
a = fire
b = fighter
a + b = firefighter
### * operator produces repeated concatenation
m = Wahoo-Wah!
n = 3
m * n = Wahoo-Wah!Wahoo-Wah!Wahoo-Wah!
n * m = Wahoo-Wah!Wahoo-Wah!Wahoo-Wah!
Terminology to which you should become accustomed
• Variable • Value • Operator | • Concatenation • Decimal division • Integer division | • Remainder • Mod • Type | • Type • Type • Type | • Keyword |
Does piaget.py (de)bug you
- Code listing
Purpose: correct errant code
Author: Jim Cohoon
Id: jpc
print( We learn best, when we must invent. -- Jean Piaget
Python arithmetic
- The Python arithmetic operators are: addition:
+
; subtraction:-
; multiplication:*
; decimal division:/
; integer division://
; exponentiation:**
; remaindering:%
- If one of the operands of an arithmetic operation is decimal, the result is decimal; otherwise, the result is integer except for decimal division.
Keywords
- Keywords are words reserved by Python for special usage; as such, they cannot be used to name things.
- For example, keyword
import
tells Python the contents of module (library) is to set up as a program resource.
To do list
- Review class artifacts
- Read and Reread
- The Coder's Apprenctice : sections 3 – 4
- And/or How to Think Like a Computer Scientist: Learning with Python 3: Sections 10.2 – 10.11
Take aways
- A video examining the ins and outs of a first program
- There are two forms of the
print()
function
- A
print()
statement with an empty parameter list produces an empty line of output
- A
print()
statement with one or more comma-separated values produces a line of output composed of the values with a single space separating one value from the next
- A literal string is a sequence of characters with in quotes (can be single or double)
- Python has two string operators
- Concatenation:
+
- Takes two strings s and t and produces a new string by first copying s and immediately following it with a copy of t
- Duplication:
*
- Takes its integer n operand and its string operand s and produces a new string that is n copies of s
- Python allows integer and decimal arithmetic operations
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Decimal division:
/
- Integer division:
//
- Exponentiation:
**
- Remaindering:
%
- If one of the operations of arithmetic operation is decimal, the result is decimal
- If an expression has more than one operation, the Python will
- First do any exponentiation operations
- Next do any multiplication, division, or remaindering operations going from left to right
- Then do any addition or subtraction operations going from left to right
- Our computers are limited in how much information they can store. Python recognizes that not all integers and decimals can be represented because there is only finite amount of memory in a machine
- Python has a type
int
. This type is for representing the best it can do with integers
- Python has a type
float
. This type is for representing the best it can do with decimals. With a 64-bit operating system, thefloat
can support at must 15 digits of precision
- Python has a type
str
. This type is for representing sequences of charactes.
We are star dust
Do you play
© 2020 Jim Cohoon | Resources from previous semesters are available. |