1 of 11

CSE 163

Introduction to Python

Suh Young Choi

🎶 Listening to: Across the Spider-Verse Soundtrack

💬 Discuss with Neighbors: Say hi! What’s your favorite summer activity?

2 of 11

This Time

  • Syllabus Q&A
  • Python Crash Course - Day 2
    • Hello world
    • Variables
    • Expressions
    • Types + Casting
    • Loops
    • Conditionals
    • Functions (parameters + returns)

Last Time (via videos)

  • Overview of class
  • Syllabus

2

3 of 11

Syllabus Q&A

Take 2 minutes to chat with your neighbors:

  • Introduce yourself
  • Discuss
    • What is something about this class that is new/unexpected?
    • What policy or part of this class do you all feel unsure about?

We will come back and answer some questions live!

3

4 of 11

Questions during Class

Feel free to raise your hand during class to ask questions! Questions are an important part of the learning process.

  • During time to work in groups, TAs and Suh Young will be walking around and can answer questions individually!
  • You can also post on the Ed Megathread for the day!

If we miss your question in class, feel free to ask after class or post on EdStem so we can answer later!

4

5 of 11

Reminder:�Motivation

We are doing this flipped classroom model this quarter. This matches results from education research on how people actually learn (hint: it’s not by listening). Requires active participation.

All the readings on Ed are written by Hunter Schafer* so you’re getting the same content as a live lecture, but in a more interactive and self-paced format.

Now this opens up free time in the class-sessions to collaboratively work with your peers on these practice problems!

* Editing credit goes to Wen Qiu, Mitchell Estberg and all TAs

5

6 of 11

Recap: Lesson

Most of lesson should have been mostly familiar (variables, if statements, etc.). Some new Python-specific things.

6

Main method pattern!

Syntax looks different!

  • Can’t explain entire grammar. Learn by looking at fragments.
  • Gets better with practice! Interact with lessons, trial and error
  • Indentation is important!

  • Colons after function and loop definitions
  • No brackets or semicolons
  • No variable type definitions

def main():

print('Hello world!')

if __name__ == '__main__':

main()

7 of 11

Recap: �Types and Casting

We introduced the following variable types in today’s lesson:

7

  • int: integers
  • float: decimal-point numbers
  • bool: True or False statements (Boolean)

Expressions:

a = 4.0

b = 3 * 2 + 4 ** 2

x = True

y = 9 < 4

Casting:

  • 3.3 -> int?
  • “3.3” -> int?
  • Other rules may apply!

8 of 11

Recap: �Loops and Conditionals

The two loops in today’s lesson:

8

  • for: runs for a fixed number of iterations
  • while: runs while a certain condition is true

Conditionals:

n = 5

if n < 10:

print(‘A’)

elif n < 20:

print(‘B’)

else:

print(‘C’)

  • Can change behavior of your function depending on certain conditions
  • Only one behavior is chosen from the branches!

9 of 11

Recap: �Anatomy of a Function

function header

9

parameters

function body

return statement

function call

10 of 11

Group Work:

Best Practices

When you first working with this group:

  • Introduce yourself!
  • If possible, angle one of your screens so that everyone can discuss together

Tips:

  • Starts with making sure everyone agrees to work on the same problem
  • Make sure everyone gets a chance to contribute!
  • Ask if everyone agrees and periodically ask each other questions!
  • Call TAs over for help if you need any!

10

11 of 11

Next Time

Quiz Section

  • Course Infrastructure
  • Testing & Debugging Process
  • Style

Lesson

  • Strings
  • Lists
  • None
  • Documenting code

Before Next Time

  • Go to section tomorrow
  • Complete the Lesson 2 reading before Friday!

11