0% found this document useful (0 votes)
818 views

Functions

This document provides instructions and examples for defining functions in Python. It includes 4 programming exercises: 1) Define a function called max_of_two() that returns the largest of two numbers. 2) Define a function called vowel() that returns True if a character is a vowel, False otherwise. 3) Define a function called shut_down() that returns a message depending on its "yes" or "no" string argument. 4) Define a function called vowel_shutdown() that calls shut_down() with a "yes" or "no" argument depending on whether the character argument is a vowel.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
818 views

Functions

This document provides instructions and examples for defining functions in Python. It includes 4 programming exercises: 1) Define a function called max_of_two() that returns the largest of two numbers. 2) Define a function called vowel() that returns True if a character is a vowel, False otherwise. 3) Define a function called shut_down() that returns a message depending on its "yes" or "no" string argument. 4) Define a function called vowel_shutdown() that calls shut_down() with a "yes" or "no" argument depending on whether the character argument is a vowel.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 1

LESSON: 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

# code goes here


return
# keep this function call here
num1 = raw_input("Enter ist Number: ")
num2 = raw_input("Enter 2nd Number: " )
num3 = raw_input("Enter 3rd Number: ")
print CheckNum(num1,num2,num3)
Examples of Output:
Input = 1,2,3 Output = 3
Input =60,12,40 Output = 60

You might also like