Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Functions and Variable Scope, Study notes of Anatomy

An introduction to Python functions, including expressions, arithmetic operators, integer division, while loops, for loops, and function definitions. It also covers variable scope and the difference between arguments and parameters. Examples and exercises are included.

Typology: Study notes

2021/2022

Uploaded on 08/05/2022

nguyen_99
nguyen_99 🇻🇳

4.2

(80)

1K documents

1 / 116

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Functions
CS106AP Lecture 6
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Python Functions and Variable Scope and more Study notes Anatomy in PDF only on Docsity!

Python Functions

CS106AP Lecture 6

Roadmap

Programming Basics^ The Console Images Data structures Midterm Graphics Object-Oriented Programming Everyday Python

Life after CS106AP!

Day 1!

Today’s questions How do we translate what we know from Karel into regular Python code? How can we make our code more flexible by producing different outputs depending on the input?

Today’s topics

  1. Introduction and Review
  2. Range For Loops
  3. Python Functions
  4. Variable Scope
  5. What’s next?

Sonja Johnson-Yu

Sonja Johnson-Yu

Sonja Johnson-Yu

Review

What is a variable?

A variable is a container for storing a data value. num_flowers = 5 num_flowers 5 variable’s name

What is a variable?

A variable is a container for storing a data value. num_flowers = 5 num_flowers 5 variable’s value

Expressions

Recall: expressions

● The computer evaluates expressions to a single value ● We use operators to combine literals and/or variables into expressions

Arithmetic operators

  • Multiplication / Division // Integer division % Modulus (remainder)
  • Addition
  • Subtraction Operator Precedence () 1 *, /, //, % 2 +, - 3 Integer division takes the largest integer that is equal to or smaller than the quotient

Integer Division Practice!

● 5 + 1 // 2 ● 9 // 3 ● 8 // 3 ● -8 // 3 Integer division takes the largest integer that is equal to or smaller than the quotient