Functions
Functions
PROGRAMMING EXERCISES
(Requires IDLE 2.7.10)
Functions - a block of organized, reusable code that is used to perform a
single, related action
#1: Max Function
Define a functionmax_of_two()that takes two numbers as arguments and returns
def - The keyword used to define a function. It's followed by the function
the largest of them.
name and parentheses () and a colon.
#2 Vowel Function
Argument - A value passed to a function when calling the function.
Define a function called vowel that takes a character (i.e. a string of length 1) and
returnsTrueif it is a vowel,Falseotherwise..
Return - statement is used to return from a function i.e. break out of the
function. We can optionally return a value from the function as well.
#3: Shutdown Function
First, def a function, shut_down, that takes one argument s. Then, if the shut_down
function receives an s equal to "yes", it should return "Shutting down" Alternatively,
elif s is equal to "no", then the function should return "Shutdown aborted". Finally, if
shut_down gets anything other than those inputs, the function should return "Sorry".
PROGRAMMING CHALLENGE # 2
(Prerequisite: Completed PygLatin Module)
#4: Vowel & Shutdown Function
Largest Number
Define a function called vowel_shutdown that takes a character (i.e. string of length
Using the Python language, have the function CheckNum(num1,num2,num3)
1). If it is a vowel call the shut_down function with a value of "yes" and return the
take three parameters and return the largest of them. If the parameter values
results of the shut_down function. Otherwise, call the shut_down function with a
are equal to each other then return the string "All values are equal"
value of "no" and return the results.
def CheckNum(num1,num2,num3):
VOCABULARY