fall 2020 — felix muzny ds 2001: practicum 1 · work on your practicum - instructions on canvas...
TRANSCRIPT
Fall 2020 — Felix Muzny
DS 2001: Practicum 1
1
Warm-up:
• All TAs like puppies. • No robots like things that TAs like. Which of the following statements can we conclude given these two pieces of information? A. All robots like puppies B. All robots like kittens C. No robots like puppies D. No robots like kittens E. All TAs like kittens
0
Today's Computing History: The Difference Engine
2
Recall: Running python programs
3
print("Hello!")python
interpreter Hello!input
(executes the program)
output
$ python hello.py
hello.pyID IDLE→Atom
kterminal
Values & Data Types
4
Type Examples
int I -13 o too
float 1.0 -13.3 0.72
string"
hi ""
cat hat" "
12"
boolean True false
Variables
5
Which of the following statements are true about variable declarations:
1. the name of the variable always goes on the right side of the "=" sign 2. you can use operators like "+" and "-" but only on the left side of the "=" sign 3. variable names may contain spaces 4. variable names are case insensitive
A. 1 & 2 B. 3 C. 4 D. 1, 2, & 4 E. None of the above
Jeff 9€NOT, rightxty=#
Variables• We use variables to save values of the results of expressions and functions
so that we can use them later (to print, to do further calculations, etc)
• When we declare a variable with a value, it allocates space in memory to store this value. We can think of the variable as the "name" that it's stored under.
6
name = value x = 12 y = 45
x
y t-
- I
The print function
• The print function is what we use to display any values or information to the user.
7
# print a value print("hello")
# print the value of a variable x = 47 print(x)
print("hello", x) # print multiple values
print(parameters)
•print 142)
var# 42
string print ("
x") # X
P
input function• We say that the input function returns a value (the user's input)
• To use this value, we must save it in a variable
• All values have a data type, including the return value
8
variable = input(prompt)
name = input("What is your name? ") print("Hello!", name) print(type(name))
①stringtix"
#
#string e.g"12"
functions - how to call them
9
return_value = function_name(arguments/parameters) Inot always included
Type Casting• functions that change a value from one type to another• Each basic type has a corresponding function that changes other values to
that type. (they return the new value)
10
dogs = input("how many dogs? ")
double_dogs = 2 * dogs print("That's so many dogs:", double_dogs)
on"
3"
dogs 13JdgE.int ( dogs) intdogs) # "
33"
Running python programs
11
Which one of these python program successfully changes ("casts") the integer value stored in the variable x to a string?
A.x = string(12)
B.str(x)
C.x = "12"
D.x = str(x)
x = 12 print(type(x)) # missing line goes here
# want this to be string print(type(x))
130
Ox -- str Cx)
Reading error messages• When you have an error, python will print out an error message. These
many *feel* like you've done something wrong, but secretly this is a great thing!
12
I
EOLTD End of Line↳ End of file
Reading error messages• When you have an error, python will print out an error message. These
many *feel* like you've done something wrong, but secretly this is a great thing!
13
-E
-
-
Work on your practicum - instructions on Canvas• Remote: we're going to put you in break out rooms of 2 - 3 people.• The TAs and myself will be moving between breakout rooms checking in• We recommend turning on your cameras and having one person screen share
as you work through the problems• (Remember that you will all individually turn in your assignment though!)• Use the "ask for help" button in zoom if you have a question and there is no
TA/Felix in your breakout room.• If your zoom crashes and you need to re-join, you'll be in the main room—we'll
keep an eye on this and re-assign you to your breakout room if this happens :) • We'll walk through one of the problems together about 15 minutes before the
end.
14