Download may11

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

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

Document related concepts
no text concepts found
Transcript
Python – May 11
• Briefing
• Course overview
• Introduction to the language
• Lab
Python
• Why computer programming?
– Computer is a general-purpose machine, born to be
programmed
– 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, python.org, tutorials
Background
• 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
Interpreted
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
continued
• Control structures
–
–
–
–
Asking questions, repeating stuff
nesting
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.
Beginning
• 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)
continued
• 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
Strings
Simple if statement
Simple loop