1 of 13

CSE 163

Introduction to Python

​

Suh Young Choi

​

🎶 Listening to: Unwed Sailor

💬 Discuss with Neighbors: Do you have a favorite animal?

​

Join Slido here!

​

Or enter

#4156356

at slido.com

2 of 13

Agenda

  • Course website tour
  • Clarification of weekly expectations
  • Intro/Review of Python

2

3 of 13

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 or Slido for the day!

​

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

​

​

​

​

​

3

Slido Q&A will be open during lecture today ☺

4 of 13

Course Website

​

  • Things to be on the lookout for:
    • Course Calendar (on the home page)
    • Lessons (in the left-hand sidebar)
    • Office Hours (in the left-hand sidebar)

4

5 of 13

Lessons and Pre-Class Work

  • Each lesson has a table of contents
  • Download files from “Setting up”

​

​

​

​

  • Before class: Read as much as you can up to “Pause and Think”

​

​

​

  • During class: Review the reading and work on “In-Class”

​

  • After class: Complete the “Canvas Quiz”

5

6 of 13

What questions do you have?

6

Slido Q&A will be open during lecture today ☺

“

7 of 13

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 13

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 13

Recap: �Anatomy of a Function

function header

9

parameters

function body

return statement

function call

10 of 13

Lesson Lowdown

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

10

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

11 of 13

Hello World!

  • Write a file called hello.py that prints “Hello World!”

​

​

11

print('Hello World!')

Attempt 1

def main():

print('Hello World!')

​

if __name__ == '__main__':

main()

​

Attempt 2

12 of 13

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!

12

13 of 13

Before Next Time

  • Go to section!
  • Complete Lesson 1 Canvas Quiz
    • Due for EC @ 11:59 pm Thu 1/8
  • Read Lesson 2 on course website
    • Read lesson. Stop after completing “Pause and Think”
    • Encouraged to save “In-class” problems for class session!
    • Due for EC @ 11:59 pm Sat 1/10

​

​

Next Time

  • Writing more Python
  • Strings
  • Lists

13