Vocab

  • A procedure is a named set of instructions that can take in parameters and return values.
    • May be called "method" or "function" in different programming languages.
  • Parameters are independent variables used in the procedure to produce a result. It allows a procedure to execute without initially knowing specific input values.

Important information

  • To call a procedure you would write the name of the procedure followed by the parentheses with the parameters of the procedure
  • Procedures do not require parameters, but the parentheses must be there
  • To determine the result of a procedure or any code, you must follow the code line by line and see what each one does

  • Using syntax, you can determine the result by

    • function parameters
    • return value and statements
  • To use return values, you have to write the syntax return followed by the expression you would like to return var
  • A return statement exits a function and instructs python to continue executing the program and to return a certain value

  • Value can be string, a tuple, or any other type that is being sent back to the main program

Topic 3.12 Hacks

  1. Define procedure and parameter in your own words
  • A procedure is a set of instructions meant to guide the code so that it can take in parameters and return values. A parameter is an independent variable that allows a procedure to execute without knowing specific values.
  1. Paste a screenshot of completion of the quiz
  2. Define Return Values and Output Parameters in your own words exits a function and tells python to keep on executing the program and to a certain value.
  3. Code a procedure that finds the square root of any given number. (make sure to call and return the function)
import math 
x = input()

print(math.sqrt(x))
print(x)
4.0
16

3.13 Layer abstraction

  1. Explain, in your own words, why abstracting away your program logic into separate, modular functions is effective
  2. Create a procedure that uses other sub-procedures (other functions) within it and explain why the abstraction was needed (conciseness, shared behavior, etc.)
  3. Add another layer of abstraction to the word counter program (HINT: create a function that can count the number of words starting with ANY character in a given string -- how can we leverage parameters for this?)

3.13 C

  1. Define procedure names and arguments in your own words. Procedure names and arguments are names that sourced procedure being defined. An procedure argument represents the value you supply to a procedure parameter when you call the procedure.
  2. Code someL (make sure they are interactive on your hacks page, allowing the user to input numbers and click a button to produce an output)
    • Add two numbers
    • Subtract two numbers
    • Multiply two numbers
    • Divide two numbers