310 likes | 569 Views
Overview of Python. Professor Frank J. Rinaldo Creation Core - office 401. Python. Textbook Python Programming for the Absolute Beginner (second edition) By Michael Dawson Premier Books 2008 ISBN: 1-59863-112-8. Introducing Python. Easy to Use Powerful Object-Oriented
E N D
Overview of Python Professor Frank J. Rinaldo Creation Core - office 401
Python • Textbook • Python Programming for the Absolute Beginner (second edition) • By Michael Dawson • Premier Books • 2008 • ISBN: 1-59863-112-8
Introducing Python • Easy to Use • Powerful • Object-Oriented • “Glue” language • Run Everywhere • Strong Community • Free & Open Source
PythonEasy to Use • Easier to use than Java, C, C++ • Simple and Clear • Easier user interface • Programs are short • 3 to 5 times shorter than Java • 5 to 10 times shorter than C++
PythonPowerful • Powerful programming language • Used at many major companies • Google • IBM • Microsoft • NASA • Industrial Light + Magic • Used by professional Game Programmers • Activision • Electronics Arts • Infogrames
PythonObject-Oriented • Fully Object-Oriented • Unlike C#, and Java, OOP is optional • Short programs need not be OO • Larger programs can be OO • Very flexible
Python“Glue” Language • Can be integrated with other languages • Extensible • Can be extended • Use subroutines / functions in other languages • Embeddable • Can be used within other languages • i.e. C++ can call Python functions
PythonRun Everywhere • Runs on Palm computers to PC’s to supercomputers • Runs on: • Windows • DOS • Macintosh • Unix / Linux • Programs are platform independent • Programs will run on any computer
PythonStrong Community • Large user group • Large support group • Open Source
PythonFree • Python is Open Source • Python is Free • Python is modifiable
Python Code • Python code is VERY similar to C/C++ and Java • VERY easy to learn • Reviewing Chapter 2 & 3 of textbook
Python Language • All Python code is on CD-ROM • Python web pages: • http://www.python.org/ • http://www.python.org/doc/ • http://www.python.org/doc/nonenglish/ • http://www.python.org/about/gettingstarted/ • Pygame – Python Games web pages: • http://www.pygame.org/news.html • http://www.pygame.org/docs/ • http://www.pygame.org/wiki/tutorials
Python Internet Resources • Beginners Information • http://wiki.python.org/moin/BeginnersGuide/Programmers • Free On-line Book – “Dive into Python” • http://diveintopython.org/ • Several Python books in Japanese • http://wiki.python.org/moin/Languages/Japanese?highlight=%28CategoryLanguage%29
Python IDLE • Integrated Development Environment • Python Editor • Helps debugging • Write, modify & save Python programs
Sample Program 1 print “Game Over” • Simple print statement • Python IS case sensitive!!
Sample Program 2 # Sum # Demo sum program # Frank Rinaldo inp = 1 sum = 0 num = 0 while int(inp) >= 0: inp = raw_input("\n\nPress a number >= 0: ") if int(inp) >= 0: sum = sum + int(inp) num = num + 1 print "The sum of ", num, " numbers is:", sum raw_input("\n\nPress the Enter key to exit.")
Output • Print Statement print “This is a print statement\n”
Input • Input Statement raw_input(“\nPress ENTER key to exit.”)
While loop • While statement sum = 0 x = 10 while x >= 0: sum = sum +x x = x – 1 • NOTE: NO ‘;’ at end of line NO ‘{‘ or ‘}’ INDENTATION used for ‘blocks’ of code
If • If statement if y < 100: y = y + 1 else: print “y is >= 100 ”,y • NOTE: use of ‘:’ & NO ‘{‘ or ‘}’
Notes • NO ‘;’ to end a statement • NO ‘{‘ or ‘}’ for blocks of code • Use indentation to indicate a block of code • Comment Statements start with a ‘#’
HOMEWORKDUE NEXT WEEK! • Write a PYTHON program to: • Find average of positive numbers • Ignore negative numbers • Stop when input is a 0 [zero] • OUTPUT sum, number of numbers, and average