Lesson 1 of 34
Lesson Progress: 0%
# function with simple output
def shout():
print("WATCH OUT!")
shout()
# function with simple output
def show_line():
print("**********")
show_line()Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
def, which is short for "define."shout().# simple function with a return
def show_color(color):
print("Your favorite color is", color)
show_color("Blue")Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
def and give it a name.color or number) is what we give to the function.print() shows a message on the screen.show_color("Blue").# simple function with a return
def add_ten(number):
print(number + 10)
add_ten(5)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
# simple function with a return
def multiply_by_two(number):
print(number * 2)
multiply_by_two(6)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
# Function to show an item and its price
def buy_item(item, price=5.0):
print("Item:", item, "| Price:", price)
buy_item("Book")
buy_item("Phone", 500.0)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
price=5.0.# Function to print a message from a specific user
def send_msg(text, user="Guest"):
print(user, "says:", text)
send_msg("Hello!")
send_msg("I am late", "Sam")Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
user="Guest" gives a default name if no name is provided.text when calling the function.print(user, "says:", text) shows who is speaking and what they said.# Function to return both the sum and difference of two numbers
def get_math(a, b):
return a + b, a - b
total, diff = get_math(10, 5)
print(total, diff)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
return to send answers back from the function.total and diff.print() shows the answers on the screen so we can see them.# Function to return both the product and division of two numbers
def get_math2(a, b):
return a * b, a / b
product, division = get_math2(12, 3)
print(product, division)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
a and b when calling the function.return a * b, a / b gives back the product and the division.# Function to return the first and last name from a list
def split_name(full_name):
first = full_name[0]
last = full_name[1]
return first, last
fname, lname = split_name(["Sam", "Smith"])
print(fname, lname)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
# Function to return a greeting and a farewell
def get_words(name):
return "Hello " + name, "Goodbye " + name
greet, bye = get_words("Alex")
print(greet, bye)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
return "Hello " + name, "Goodbye " + name makes two messages using the name.greet, bye = stores the two results into two variables.Test Incomplete