Outline for October 6, 2020
Reading
: §2, 3.7
Due
: Homework 1, due October 15, 2020
Variables
What they are
Variable names
Variable types (int, float, string)
Function
type()
Python keywords
Variables
Legal names
Keywords
How to pick variable names
Simple assignment:
variable = expression
Expressions
Operators
+
,
-
,
*
,
/
,
//
,
%
,
**
Precedence
Parentheses for grouping (
(
,
)
)
Exponentiation (
**
); associates right to left
Positive, negative (unary
+
,
-
)
Multiplication, division, integer division, remainder (
*
,
/
,
//
,
%
)
Addition, subtraction (binary
+
,
-
)
In general, operators of equal precedence are evaluated from the left to the right (associativity); exception noted above
Example
Compute the hypotenuse of a right triangle [
hypot.py
]
The difference between strings and integers [
twoplustwo.py
]
Difference between
'2 + 2'
,
2 + 2
Type converter functions
int
,
float
,
str
String operators
Operator
+
: string concatenation
Operator
*
: repetition
Input: input statement
input(prompt)
prints prompt, waits for user
When user hits enter, it returns what was typed as a string
Exceptions
Division by zero [
divby0.py
]
Typing letters when a number is expected [
hypotex.py
]
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
mabishop@ucdavis.edu
MHI 289I, Programming for Health Informatics
Version of October 6, 2020 at 8:02AM
You can also obtain a PDF version of this.