Intro to CS - Errors and IDLE setup

Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Getting Started with Python: 

Getting Started with Python Introduction to Computer Science Mr. Good

Discussion: 

Something interesting from the articles yesterday? Discussion

What is a program?: 

“A program is a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or (strangely enough) compiling a program.” ( Chapter 1 of Think Python ) Programs do all of this using: Input Output Math Conditional Execution Repetition That’s it. Really. No kidding. What is a program?

Debugging and Errors: 

Debugging – the process of fixing errors Errors – when a program does not work as you intended 3 Types of errors Syntax Runtime (also referred to as ‘exceptions’) Semantic Debugging and Errors

Syntax Errors: 

You did not use the correct ‘syntax’ for writing a line of code Can be various things: Misspelled command Missing parentheses Incorrect use of a symbol Endless possibilities In the English language, a syntax error would be a misspelled word or improper punctuation. (Ex: Computr ) Syntax Errors

Runtime Errors: 

You have gone beyond the bounds of what Python and/or your machine can do. There are physical limits to what a computer’s memory or disk storage can hold Different languages may have different limits built into them The program can be written to hit these limits, thus causing an error. Art Example: “I set the kiln to the temperature of the sun” Runtime Errors

Semantic Errors: 

Your program runs, but it doesn’t do what you intended it to do. All your code runs You aren’t getting the output you expected Culinary Arts example: “I mixed water, Kool Aid flavoring, and 1 cup of salt. I made a drink. It was not the drink I was expecting.” Semantic Errors

Why Python?: 

It fits our goals Learn basic to intermediate programming concepts Ability to pick up other languages NOT to memorize a language in its entirety Apply to real world application (Maple, Robotics, Fun) Python’s advantage over other common languages Somewhat forgiving syntax. Helpful error messages. C++, Java, not this way E asier to learn concepts and not get hung up on syntax Used by professional programmers (applicability) Multitude of free libraries (Ex: Google and NXT Robotics) Monty Python Fans? Watch for references in books and language. Why Python?

IDLE (Interactive Development Environment): 

Eric Idle – first geeky MP reference Script vs. Interactive Mode Interactive – helpful when building, but not the final form Script – saving an entire program and running it at will Python version 2 vs. version 3 Think Python – version 2 Head First Programming – version 3 We’ll be using version 3 Mac / Windows Code will run the same Some libraries may have slight differences Depending on others’ code IDLE (Interactive Development Environment)

Let’s Begin: 

http://python.org/download / Windows Users – download and install the Windows Binary for Python 3.2.1 Mac Users - If you have not updated to Lion in the last two months, install the Mac OS 32 bit i386/PPC installer Mac Users with Lion – install the Mac OS 64 bit installer Look in Programs (Windows) or Applications (Mac) for Python 3.2 folder. Open and start IDLE. Let’s Begin

IDLE in Interactive Mode: 

Usually just type one command at a time. Good for experimenting with and debugging code This is also where output from programs will show up. IDLE in Interactive Mode

Lab 1: 

Install Python on your home computer Write a Hello World program Also have it output your favorite color, food, and season Save the file as LASTNAME _Lab1.py (Example for Mr. Good = Good_Lab1.py) and put it in the drop box. HINT: Chapter 1 of Think Python – read it The book uses version 2 Python, so be careful when copying code. The version 3 PRINT command is actually written like this example: print (’Electric Penguin' ) Lab 1