Functions Checklist

1) Define a function that prints two sentences. Call that function in your main program so it will be executed every time you click “run.”

2) Define a function that receives a 0 to 100 grade and returns either “pass” or “fail.”

Call the function from your terminal using several different arguments to prove that it works correctly in each case. The terminal is the right side of a repl.it screen.

Example Terminal Output:

passfail(100)   
pass

passfail(35)
fail

passfail(0)
fail

passfail(99)
pass

passfail(60)
pass

passfail(59)
fail

3) Create a program that outputs the circumference of a circle when the diameter is given.

The function must have a return statement as its last line of code.
The function may NOT have any print statements.

At the end of your program, after the function definition, call the circumference function three times with different input values. Print those values.

4) Using your circumference function, create a list of circumferences calculated from the list of diameters in the starter code. Use a for loop to iterate through the diameters list. Print the diameters list. (hint: circumferences += [something])

diameters = [3, 0.25, 100, 0.92, 7.1]
circumferences = []
#write loop code here
print(circumferences)

5) Create a function that creates a grid of  * characters that’s however long and wide the user specifies.

It should work something like this if you use it from Python Console:

>>>grid(2, 4)
**
**
**
**

>>>grid(12, 3)
************
************
************

6) Create a program with an adding function and a subtracting function. Ask the user to enter two numbers, then ask if they want to add or subtract. Do the math they request.

No print statements are allowed in your add and subtract functions. Return a value instead. Print the answer in the body of the program instead.

Starter Code:

#Define your two functions at the top
#The first function is started, but you finish it

def add(a,b):
    #add code
    return #add code

x = input('Enter your first number: ')
y = input('Enter your second number: ')
op = input('Add or subtract?')
#if/elif/else statements go here
#call your add or subtract functions in the if/elif/else branches
#example: print(add(x,y))

7)Define a function that analyzes a piece of writing as follows:
a) Counts the number of words (count spaces or use split() function)
b) Counts the number of alphabet letters
c) Calculates the average word length

The function should print the results.

Starter Code:

def analyze(text):
#write function code

text = input('Type some text: ')
analyze(text)

Example Output:

Type some text:  I eat cake when I'm happy.
Text has 19 letters.
Text has 6 words.
Average word length is 3.1666666666666665