Skip to content
Snippets Groups Projects
Commit 3fb285f4 authored by Andy Kuemmel's avatar Andy Kuemmel
Browse files

Deleted...

Deleted f22/andy_lec_notes/lec05_Sep16_UsingFunctions/.ipynb_checkpoints/lec_05_template-checkpoint.ipynb
parent 86c8011d
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
# Warmup:
# Use the ** operator to calculate the square root of 17
# Use type to print out the type of the answer
```
%% Cell type:markdown id: tags:
### September 17: Expressions and Variables
Learning Objectives:
- 5.1 Evaluate Expressions
- by identifying operators and operands
- by identifying literal values and variables
- by identifying the correct order of operations
5.2 Write assignment statements with proper syntax
- Start with a variable name that follows proper rules for variables
- Use a single equals sign
- Finish with an expression
5.3 Define, give examples of, and identify 3 kinds of errors
- Syntax error
- Runtime error
- Semantic error
5.4 Write Python code that computes with strings ints, floats, and Boolean types
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
# Trick expression #1: What will this evaluate to:
# 1+1 ==2 or 3 ** 10000000 > 2 ** 20000000
```
%% Cell type:code id: tags:
``` python
# 3 ** 10000000 > 2 ** 20000000
```
%% Cell type:code id: tags:
``` python
# 1 + 1 == 2 or 4 / 0
```
%% Cell type:code id: tags:
``` python
# 4 / 0 or 1 + 1 == 2
```
%% Cell type:code id: tags:
``` python
# False or True
```
%% Cell type:code id: tags:
``` python
# These examples might seem weird but they preview the kinds of errors
# students make in their code
```
%% Cell type:code id: tags:
``` python
# False or "hi"
```
%% Cell type:code id: tags:
``` python
# 3 + 4 == 7 or 6 # Incorrect conditions
```
%% Cell type:code id: tags:
``` python
# 3 + 4 == 6 or 7 # Incorrect conditions
```
%% Cell type:code id: tags:
``` python
# 3 + 4 == 6 or 8 # Incorrect conditions
```
%% Cell type:code id: tags:
``` python
# 3 + 4 == 6 or 3 + 4 == 7 #Correct conditions
```
%% Cell type:code id: tags:
``` python
x = 10
print(x)
```
%% Output
10
%% Cell type:code id: tags:
``` python
x + 1
```
%% Output
11
%% Cell type:code id: tags:
``` python
x = x + 3
print(x)
```
%% Output
13
%% Cell type:code id: tags:
``` python
x += 3
```
%% Cell type:code id: tags:
``` python
x -= 1
```
%% Cell type:code id: tags:
``` python
# 5 = x # Syntax error
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
# int demo
# Print out hours, minutes, and seconds
seconds = 12345
hours = 0
print(hours)
seconds = 0
minutes = 0
print(minutes)
seconds = 0
print(seconds)
```
%% Output
0
0
0
%% Cell type:code id: tags:
``` python
# float demo
# Compound growth
start = 1000
interest = 7
years = 30
yearly_mult = 1 + interest / 100
final = start * (yearly_mult ** years)
print(final)
```
%% Output
7612.255042662042
%% Cell type:code id: tags:
``` python
# str demo
# Alice vs Bob
player1_name = 'Alice'
player2_name = 'bob'
player1_score = 10
player2_score = 8
#Scores are difficult to compare
print(player1_name + ': ' + '|' * player1_score)
print(player2_name + ': ' + '|' * player2_score)
#Assuming name has a maximum of 9 characters
#Now scores are easier to read and compare
print(player1_name + ': ' + " " * (9 - len(player1_name)) + '|' * player1_score)
print(player2_name + ': ' + " " * (9 - len(player2_name)) + '|' * player2_score)
```
%% Output
Alice: ||||||||||
bob: ||||||||
Alice: ||||||||||
bob: ||||||||
%% Cell type:code id: tags:
``` python
# bool example
age = 10
valid = 0 <= age <= 100
print("you may continue: " + str(valid))
```
%% Output
you may continue: True
%% Cell type:code id: tags:
``` python
# bool example
age = 110
valid = 0 <= age <= 100
print("you may continue: " + str(valid))
```
%% Output
you may continue: False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment