Home
Acrobat
Contents
1. Don t Forget How To Succeed In This Course Practice things yourself Make sure that you keep up with the material Look at the material before coming to lecture Start working on things early James Tam Computer Programs Binary 1s the language of the computer Translator e g python 3 An m executable 1 A programmer program is writes a computer 2 A translator created pr SES converts the program into a form that the ul computer can SE understand 4 Anybody who has this executable installed on their computer can run use it James Tam Translators Convert computer programs to machine language Types 1 Interpreters e Each time that the program is run the interpreter translates the program translating a part at a time e If there are any errors during the process of interpreting the program the program will stop running right when the error is encountered 2 Compilers Before the program is run the compiler translates the program compiling it all at once If there are any errors during the compilation process no machine language executable will be produced If there are no errors during compilation then the translated machine language program can be run James Tam Python This is the name of the programming language that will be used to illustrate programming concepts this semester e My examples will be written in Python e Your assignments will be written in Python Some advantages e F
2. Python requirement and should not begin with an underscore style requirement e Can t be a reserved word or a keyword e Names are case sensitive but avoid distinguishing variable names only by case bad style e Variable names should generally be all lower case For variable names composed of multiple words separate each word by capitalizing the first letter of each word save for the first word or by using an underscore Be consistent Constants Memory locations that shouldn t change Used to make the program easier to read and understand PI 3 14 Differentiated from variables by capitalization Multi vvord constants can use the underscore to separate words e g MAX SIZE 10 Displaying The Contents Of Variables And Constants Format print lt variable name gt print lt constant name gt Example aNum 10 aCONSTANT 10 print aNum print aCONSTANT Mixed Output Mixed output getting string output and the contents of variables or constants to appear together Format print string lt variable or constant gt Examples mylnteger 10 myReal 10 5 myString hello print MyInteger myInteger print MyReal myReal print MyString myString Arithmetic Operators e qe C e e Augmented Assignment Operators Shortcuts Operator Long example Augmented Shortcut PT Program Documentation Program documentation Used to provide information abou
3. Getting Started With Python Programming How are computer programs created Variables and constants Input and output Operators Common programming errors Advanced techniques for formatting text output Reminder About The Course Textbook It s recommended but not a required purchase However the course notes are required for this course Reminder How To Use The Course Resources They are provided to support and supplement this class eNeither the course notes nor the text book are meant as a substitute for regular attendance to lecture and the tutorials T AS LS ES James Tam Reminder How To Use The Course Resources 2 procedure add var head NodePointer var newNode NodePointer var temp NodePointer begin if head NIL then head newNode else begin temp head while temp next lt gt NIL do temp temp next temp next newNode end newNode next NIL end James Tam Reminder How To Use The Course Resources 2 procedure add var N NodePointer S ngg Node NodePointer qe var N or of REA MET xe EI 0 Og N T ady Qe N neg SFr Node b o NS co in temp head while temp next lt gt NIL do temp temp next temp next newNode end newNode next NIL end But Once You ve Made An Attempt To Catch Up Ask for help if you need it There are no dumb questions Image from The Simpsons Fox
4. is incorrect it doesn t do what it s supposed to and may produce an incorrect result You can find an online version of this program in the UNIX file system under home courses 217 examples intro logic py print This program will calculate the area of a rectangle length input Enter the length width input Enter the width area length width print Area area Advanced Text Formatting Triple quoted output Using escape sequences Triple Quoted Output e Used to format text output The way in which the text is typed into the program is exactly the way in which the text will appear onscreen You can find an online example of triple quoted output in the UNIX file system under home courses 2 17 examples intro formatting 1 py From Python Programming 274 Edition by Michael Dawson James Tam Escape Codes The back slash character enclosed within quotes won t be displayed but instead indicates that a formatting escape code will follow the slash E Alarm Causes the program to beep e eee Moves the cursor back one space E aa Moves the cursor to beginning P ainkoa daalena the next line Tab Moves the cursor forward one tab stop Single quote Prints a single quote Double quote Prints a double quote Backslash Prints one backslash James Tam Escape Codes 2 You can find an online version of this program in the UNIX file system under home courses 2 17 examples intr
5. o formatting2 py print a Beep print h bello print hi nthere print it s print he y you You Should Now Know What is the difference between the two types of translators compilers and interpreters How to create translate and run Python programs on the Computer Science network Variables What are they and what are they used for How to access and change the value of a variable e Conventions for naming variables Constants What are constants and how do they differ from variables e What are the benefits of using a named constant You Should Now Know 2 How are common mathematical operations performed in Pascal Output e How to display text messages or the value of a memory location variable or constant onscreen with print Input e How to get a program to acquire and store information from the user of the program What are the three programming errors when do they occur and what is the difference between each one You Should Now Know 3 How triple quotes can be used in the formatting of output What is an escape code and how they can affect the output or execution of a program
6. ompiled programs e g C C Pascal translation occurs before the program is executed because compilation occurs all at once before execution e For interpreted programs e g Python translation occurs as each statement in the program is executing because interpreting occurs just before each statement executes 1 Some Common Syntax Errors Miss spelling names of keywords e e g primt instead of print Forgetting to match closing quotes or brackets to opening quotes or brackets Using variables before they ve been named allocated in memory You can find an online version of this program in the UNIX file system under home courses 2 17 examples intro syntax py print num 2 Runtime Errors Occur as a program is executing running The syntax of the language has not been violated each statement follows the rules syntax During execution a serious error 1s encountered that causes the execution running of the program to cease A common example of a runtime error is a division by zero error 2 Runtime Error An Example You can find an online version of this program in the UNIX file system under home courses 2 17 examples intro runtime py num input Type in a number num3 input Type in a number numl num num3 print numl 3 Logic Errors The program has no syntax errors The program runs from beginning to end with no runtime errors But the logic of the program
7. ons The purpose of this description is to help the reader quickly understand how the program works James Tam Program Documentation 3 Format lt Documentation gt The number sign H flags the translator that what s on this line is documentation Examples Tax It v1 0 This program will electronically calculate your tax return This program will only allow you to complete a Canadian tax return James Tam Input The computer program getting information from the user Format lt variable name gt input OR lt variable name gt input lt Prompting message gt Example print Type in a number num input OR num input Type in a number James Tam Types Of Programming Errors 1 Syntax translation errors 2 Runtime errors 3 Logic errors 1 Syntax Translation Errors Each language has rules about how statements are to be structured English sentence is structured by the grammar of the English language e The cat sleeps the sofa Grammatically incorrect missing the preposition to introduce the prepositional phrase the sofa Python statements are structured by the syntax of Python e num Syntactically incorrect the left hand side of an assignment statement cannot be a literal constant 1 Syntax Translation Errors 2 The translator checks for these errors when a computer program is translated to binary For c
8. ree e Powerful e Widely used Google NASA Yahoo Activision Electronic Arts etc Named after a British comedy Monty Python BBC Online documentation http www python org doc James Tam An Example Python Program You can find an online version of this program in the UNIX file system under home courses 217 examples intro small py Filename small py print hello James Tam Creating Translating And Executing Python Programs _ To begin creating a Python program in Text editor Unix type XEmacs filename py _ Python interpreter To interpret and execute the Effect of execution program in Unix type python Message appears filename py onscreen File is opened Etc James Tam Displaying String Output String output A message appears onscreen that consists of a series of text characters Format print the message that you wish to appear Example print foo print bar James Tam Variables Set aside a location in memory Used to store information temporary e This location can store one piece of information e At most the information will be accessible as long as the program runs Some of the types of information which can be stored in variables Integer e Real numbers e Strings Picture from Computers in your future by Pfaffenberger B James Tam Variable Naming Conventions e Should be meaningful Names must start with a letter
9. t a computer program to another programmer e Often written inside the same file as the computer program when you see the computer program you can see the documentation e The purpose is to help other programmers understand how the program code was written how it works what are some of it s limitations etc User manual Used to provide information about how to use a program to users of that program e User manuals are traditionally printed on paper but may also be electronic but in the latter case the user manual typically takes the form of electronic help that can be accessed as the program is run e The purpose is to help users of the program use the different features of the program without mention of technical details James Tam Program Documentation 2 It doesn t get translated into binary It doesn t contain instructions for the computer to execute It is for the reader of the program What does the program do e g tax program What are it s capabilities e g 1t calculates personal or small business tax e What are it s limitations e g it only follows Canadian tax laws and cannot be used in the US e What is the version of the program If you don t use numbers for the different versions of your program then consider using dates e How does the program work This is often a description in English or another high level language that describes the way in which the program fulfills its functi
Download Pdf Manuals
Related Search
Related Contents
Cooper Lighting LTC2 Series User's Manual Vivitek D825M Serie User Manual English San Francisco Cap Santé 49 DSG-423 Service Manual - Coulson Compression & Measurement dossier_presse_DAF_21-09-10 - Direction de l`Alimentation, de l Liebert Interceptor H2120Y444R-03 User's Manual Operator, Parts and Service Manual Manufactured By Copyright © All rights reserved.
Failed to retrieve file