Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.

Similar presentations


Presentation on theme: "CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz."— Presentation transcript:

1 CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz

2

3 Semantic vs. Syntax Syntax: The formal rules for legal statements in the language. Semantics: The meaning of the statements - what happens when the statement is executed. Source: Here

4 Programming Errors Syntax Semantic (Logical) Run-Time
Syntax errors are mistakes in the use of the python language, and are analogous to spelling or grammar mistakes in a language like English. Common syntax errors include: leaving out a keyword Leaving out a ; putting a keyword in the wrong place leaving out a symbol, such as a colon, comma or brackets misspelling a keyword Program does not run until you fix these errors. Logical errors are the most difficult to fix. They occur when the program runs without crashing, but produces an incorrect result. Common logical errors include: using the wrong variable name getting operator precedence wrong making a mistake in a boolean expression off-by-one, and other numerical errors Program run until the end, but it gives wrong results. A problem which was not detected when the program was parsed, but is only revealed when a particular line is executed. Common run-time errors include: division by zero performing an operation on incompatible types accessing a list element, dictionary value or object attribute which doesn’t exist trying to access a file which doesn’t exist. Program is terminated unexpectedly while it is running. It does run all the code. Source: Here

5 Identifiers Identifiers are names of various program elements in the code that uniquely identify the elements. They are the names of things like variables or functions to be performed. They're specified by the programmer and should have names that indicate their purpose.

6 Identifiers Rules Are made of letters, digits and underscores.
Must begin with a letter or an underscore Does not have a space Can take any length. Not a reserved word (keywords). It is case sensitive. Use meaningful name.

7 Keywords keyword: An identifier that you cannot use, because it already has a reserved meaning in the python language. Complete list of python keywords: False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise

8 Strings and string literals
string: A sequence of text characters (not just letters) that can be printed or manipulated in a program. literal: a representation of a value of a particular type String literals in python start and end with quotation mark characters "This is a string"

9 Comments

10 Comments Comments can be put in many standard places.
Most all programs have a "comment header" at the top of each file, naming the author and explaining what the program does. Most programmers also place a comment at the start of every method, describing the method's behaviour. Lastly, we can use comments inside methods to explain particular pieces of code. Comments provide important documentation. At this stage in our learning, it is not very useful to write comments, because we only know println statements. More complicated programs span hundreds or thousands of lines, and it becomes very difficult to remember what each method is doing. Comments provide a simple description. When multiple programmers work together, comments help one programmer understand the other's code.

11 Comments If we have # anywhere on a line, everything following this on the line is a comment – ignored. For more than a line, put your comments between ‘‘‘ Put your comments here On multiple lines


Download ppt "CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz."

Similar presentations


Ads by Google