Search Header Logo
Python Functions - Introduction

Python Functions - Introduction

Assessment

Presentation

•

Computers

•

Professional Development

•

Hard

Created by

Sandra Eugenia Barajas Montiel

Used 10+ times

FREE Resource

14 Slides • 4 Questions

1

media

2

media

3

media

4

media

5

media

​Learning Target: I can write my own functions, use them in my code, explain why they make my programs easier to manage, and fix mistakes in function definitions.

6

Yeah

I've been tryna call
I've been on my own for long enough
Maybe you can show me how to love, maybe
I'm goin' through withdrawals
You don't even have to do too much
You can turn me on with just a touch, baby

I look around and
Sin City's cold and empty (oh)
No one's around to judge me (oh)
I can't see clearly when you're gone

I said, ooh, I'm blinded by the lights
No, I can't sleep until I feel your touch
I said, ooh, I'm drowning in the night
Oh, when I'm like this, you're the one I trust
(Hey, hey, hey)

I'm running out of time
'Cause I can see the sun light up the sky
So I hit the road in overdrive, baby, oh

The city's cold and empty (oh)
No one's around to judge me (oh)
I can't see clearly when you're gone

I said, ooh, I'm blinded by the lights
No, I can't sleep until I feel your touch
I said, ooh, I'm drowning in the night
Oh, when I'm like this, you're the one I trust

I'm just walking by to let you know (by to let you know)
I could never say it on the phone (say it on the phone)
Will never let you go this time (ooh)

I said, ooh, I'm blinded by the lights
No, I can't sleep until I feel your touch
(Hey, hey, hey)
(Hey, hey, hey)

I said, ooh, I'm blinded by the lights
No, I can't sleep until I feel your touch

​Source: Musixmatch Songwriters: Martin Karl Sandberg / Jason Quenneville / Oscar Thomas Holter / Ahmad Balshe / Abel Tesfaye

7

media

8

Fill in the Blanks

Functions are really powerful programming constructs because they let us _____ ______​

​ of code

that we have already written. This helps us manage the complexity of our programs because it can ​

______ ​ the amount of code that we need to write​ . It also helps make our programs easier to __________ ​

​

and consequently maintain, because functionality is more clearly separated within our programs.

9

media

10

11

media

12

Fill in the Blanks

#COMPLETE THE FUNCTION DEFINITION

def calculate_profit( _ ):

# Calculate the profit using the formula P(x)

profit = (-8* (x ** 2)) + (3200 * x) - 16000

# Return the final calculated profit

return

13

Fill in the Blanks

#COMPLETE THE FUNCTION CALL

apartmentsrented1 = 30

_____________ = calculate_profit(_________________)

print("If",apartmentsrented1," apartments are rented, the profit is: $",profitresult1)

14

Function Requirements

  1. Function Name: calculate_total_cost

  2. Parameters: The function must accept exactly two parameters in the following order:

    • quantity (an integer representing the number of items).

    • unit_price (a float representing the cost of one item).

  3. Calculation: The function must return the result of quantity * unit_price.

You are working as a junior developer for "SupplyChain Solutions," a company that provides inventory tracking software to small businesses. A core requirement of their application is the ability to instantly calculate the total cost of any given purchase order.

-The total cost is calculated by multiplying the quantity of items ordered by the unit price of that item.

Your task is to implement a reusable Python function that performs this critical calculation.

15

media

16

Multiple Choice

Question image

The code highlighted in blue is best defined as:

1

function name

2

function call

3

function definition

4

arguments

5

parameters

17

media

18

media
pattern-tertiary
media

Show answer

Auto Play

Slide 1 / 18

SLIDE