0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Functions can have multiple parameters ("parameter" being a fancy word for "input"). For example, this subtract
function accepts 2 parameters: a
and b
.
def subtract(a, b):
result = a - b
return result
The name of a parameter doesn't matter when it comes to which values will be assigned to which parameter. It's position that matters. The first parameter will become the first value that's passed in, the second parameter is the second value that's passed in, and so on. In this example, the subtract
function is called with a = 5
and b = 3
:
result = subtract(5, 3)
print(result)
# 2
Here's an example with four parameters:
def create_introduction(name, age, height, weight):
first_part = "Your name is " + name + " and you are " + age + " years old."
second_part = "You are " + height + " meters tall and weigh " + weight + " kilograms."
full_intro = first_part + " " + second_part
return full_intro
It can be called like this:
my_name = "John"
my_age = "30"
intro = create_introduction(my_name, my_age, "1.8", "80")
print(intro)
# Your name is John and you are 30 years old. You are 1.8 meters tall and weigh 80 kilograms.
We need to calculate the total
damage from a combo of three damaging attacks. Complete the triple_attack
function by returning the sum of its parameters, damage_one
, damage_two
, and damage_three
.
The attacks (attack_one
to attack_six
) are already passed to two triple_attack
function calls for you, so you do not need to use them directly in the function.
Focus Editor
Alt+Shift+]
Login to Submit
Login to Run
Login to view solution