bembry.org
Home / Technology / Python / Notes

Lesson 2: The Way of the Program: Let's Start Programming

  • Overview
    • Natural vs. Formal language
    • Rules of Syntax
    • Debugging
    • First program
  • Natural Language
    • Spoken by people (English, Hebrew, Spanish)
    • Ambiguous
      • “Give me the thing”, “Oh, sure.”, “Great!”
    • Redundant
    • Filled with idioms (not literal)
      • “I could eat a cow”, “You’re killing me”, “Go fly a kite”
  • Formal Language
    • Man-made
      • Math, Chemistry, Computer Programming
    • Unambiguous
      • 1+4=5
      • CH4 + 2O2 --> 2H2O + CO2
      • Print “Hello world”;
    • Concise
    • Literal
  • Languages have rules of Syntax
    • Tokens
      • Basic elements (letters, words, symbols)
      • Good Tokens: 1+3=4 ; CAT; H2O
      • Bad Tokens: 2@+#=!; C€§; HhO
    • Structure
      • The way tokens are arranged
      • Good Structure: 1+3=4; CAT; H2O
      • Bad Structure: 13+=4; CTA; 2HO
  • Debugging
    • Errors in a program are called “bugs”
    • Debugging is the process of tracking down errors and fixing them
    • Debugging is one of the most important skills in programming
  • Three main types of bugs:
    • Syntax Errors
      • Using a token or structure that is incorrect
      • Program will quit with an error message
    • Run-Time Errors
      • Error that occurs during execution
      • Program will quit running
    • Logic Errors
      • Error in how program is logically constructed
      • Program runs, but does wrong thing
  • Python: Interpreter vs Scripting
    • Interpreter:
      • Immediate feedback
      • Code not saved
    • Scripting:
      • Code saved
      • Feedback delayed
      • More debugging required
  • Scripting Basics
    • Type in “Idle”, Notepad, or text editor
    • Save as .py
    • To run:
      • Open a DOS command prompt
      • Navigate to the directory with the file
      • Type "yourfile.py”
  • Review
    • What is the difference between a natural and formal language?
    • What are tokens and structure?
    • What are the three main types of bugs?
    • What is the difference between creating a Python script and working in the interpreter?
    • Use the Python interpreter to perform basic calculations.
    • Create 2 scripts in Python, one math, one “Hello world”
Restricted access