DS 2001: Practicum 1 Warm-up: All TAs like puppies. No robots like - - PowerPoint PPT Presentation

ds 2001 practicum 1
SMART_READER_LITE
LIVE PREVIEW

DS 2001: Practicum 1 Warm-up: All TAs like puppies. No robots like - - PowerPoint PPT Presentation

Fall 2020 Felix Muzny DS 2001: Practicum 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.


slide-1
SLIDE 1

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
slide-2
SLIDE 2

Today's Computing History: The Difference Engine

2
slide-3
SLIDE 3

Recall: Running python programs

3

print("Hello!") python interpreter Hello! input (executes the program)

  • utput

$ python hello.py hello.py

ID IDLE

→ Atom

k

terminal

slide-4
SLIDE 4

Values & Data Types

4

Type Examples

int

I

  • 13
  • too

float

1.0

  • 13.3

0.72

string

" hi

"

"

cat hat

"

"12

"

boolean

True

false

slide-5
SLIDE 5

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=#

slide-6
SLIDE 6

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
slide-7
SLIDE 7

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

slide-8
SLIDE 8

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))

string

tix

"#

# string e.g

"12

"

slide-9
SLIDE 9

functions - how to call them

9

return_value = function_name(arguments/parameters)

I

not always included

slide-10
SLIDE 10

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)

  • n
"3

"

dogs 13J

dgE.int (dogs)

intdogs)

#

"33

"

slide-11
SLIDE 11

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

O

x

  • str Cx)
slide-12
SLIDE 12

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

slide-13
SLIDE 13

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
slide-14
SLIDE 14

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