Download may11

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Python – May 11
• Briefing
• Course overview
• Introduction to the language
• Lab
• Why computer programming?
– Computer is a general-purpose machine, born to be
– We want to solve many types of problems
• Our goals
– Become multi-lingual
– Practice with design & implementation
– Learn by doing: start simple
• Help available
– Textbook,, tutorials
• First released, 1991
– Guido van Rossum, CWI, Netherlands
– Dissatisfaction with existing languages
• High-level, multi-purpose language
Relatively easy to learn & use (we hope!)
Procedural, object oriented or functional
Interface to OS, file system, Web
Some data structures built into language
Standard library
(More details in sections 1.3 and 1.5)
Initial To-Do
Essential skills; special features of language
• Routine stuff
– Source file name ends in .py
– How to run interpreter (command line or IDE)
– Program structure
• I/O
– Interactive, file; formatting
• Variables, identifiers
• Doing math
• Comments, tokens, whitespace, style conventions
• Control structures
Asking questions, repeating stuff
How to make comparisons
Boolean operations: and/or/not
• Functions/procedures: parameters, returns
• Data structures
– String, dynamically-sized list, etc.
• Standard (i.e. run-time) library
– Random numbers, etc.
In the end…
• How can you tell if you’ve mastered a language?
Write a game
Given a spec or algorithm, can you implement it?
You may prefer to do something in Python!
You never need to know everything. Know where to
find stuff quickly
• This course lies between first 2 prog. courses
– You’ll see more operations & applications than in the
1st course. Not as theoretical as 2nd course.
• Versions 2.x and 3.x
• Lab: let’s use IDE such as ActivePython
– Free, simple, includes debugger 
• Code can by entered:
– directly in shell (good for experimenting!)
– in a file, which we can save and reuse later
Initial nuts & bolts
Comments begin with #, go to end of line
Statements don’t end in semicolon
Don’t arbitrarily indent code
Put \ at end of line to continue statement
Variables are not declared
• Interactive output
– Version 2.6: print statement
– Version 3.0: print function
print name
print (name)
• Examples
print “Hello, world”
print 7+4*3
• Interactive input
– input( ) for getting a number
– raw_input( ) for getting a string
name = raw_input(“What is your name”)
What’s next?
• Lab
• Please read chapter 2
• Practice with
Basic I/O
Mathematical operations
Simple if statement
Simple loop