programming-fundamentals
  • Introduction
  • Lesson 1
    • Writing Your First Program
    • Data Types
    • Built In Functions
    • If Statements
    • Using Git and Github
    • Primer
    • Questions
    • Tip Calculator
    • GPA Calculator (optional)
  • Lesson 2
    • Modules
    • Lists
    • Data Structures
    • More On Data Structures
    • Questions
    • Madame Zamad
    • Mad Libs
  • Lesson 3
    • While Loops
    • For Loops
    • Loops and Lists
    • Special Commands
    • Questions
    • TODO List
    • Fibonacci (optional)
  • Lesson 4
    • Functions
    • More Functions
    • Error Handling
    • File I/O
    • Questions
    • Sudoku
Powered by GitBook
On this page

Was this helpful?

  1. Lesson 4

Questions

  • Why should we use functions in our programs?

  • True or False, the function below is incorrect because the variable name used

    within the function is different than the variable name defined outside.

def launch(item):
  print("item launched: %s".format(item))

missile = 'warhead'
launch(missile)
  • True or False, even functions with no return statement return a value?

  • Write a function that combines two strings and returns the result.

  • How could you rewrite the following code using a function?

hole = None
if peg_type == 'round':
  print('the type supplied is round')
  hole = 'round'
elif peg_type == 'square':
  print('the type supplied is square')
  hole = 'square'
  • True or False, when calling a function, the order in which you supply

    arguments (the values you are giving to the function in parentheses) is

    critical?

  • Give an example of overriding scope.

  • How can you recover from a fatal error on your program?

  • Give an example of handling an IndexError.

  • Why would we care to write our data to a file?

  • How can I open a file in read/write mode?

  • What would I do if I wanted to read a file one line at a time?

PreviousFile I/ONextSudoku

Last updated 5 years ago

Was this helpful?