Prog D1 - UOPEOPLE programming fundamental discussion assignment unit 1 PDF

Title Prog D1 - UOPEOPLE programming fundamental discussion assignment unit 1
Author Ganda Selenu
Course Programming Fundamentals
Institution University of the People
Pages 2
File Size 60.3 KB
File Type PDF
Total Downloads 6
Total Views 129

Summary

UOPEOPLE programming fundamental discussion assignment unit 1...


Description



>>> print 'Hello, World!' SyntaxError: invalid syntax The SyntaxError means there is a problem with the statement. In running python 3, print is a function as such there must be a parenthesis that shows that. For instance, in the example above there is no parenthesis as such the interpreter displayed SyntaxError. >>> print('Hello, World!') Hello, World! The example above is the one I took from the textbook. The only difference between the previous statement and this one is the presence of a parenthesis (bracket). This showed that the computation is done in Python 3 and as such for every print statement, there must be a parenthesis since it is a function.



>>> 1/2 0.5 This statement is correct due to the presence of legal tokens and the proper combination of the token. The arithmetic operator is properly used as such the interpreter displayed the right result which means the computation is that of an arithmetic operation.



>>> type(1/2)

The statement is valid. This is because the appropriate tokens and values are used. The usage of “type” indicates the category the value belongs to. Value may be letters or numbers. For instance the input above displayed the output . The “class” signifies the type of value it is, which is “floating point number”.



>>> print(01) SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers. The bug in the input above is the leading zero. Formal language is designed to be unambiguous and literal (it has only one meaning irrespective of context). Although the input is correct in math notation, however, it is an illegal token in python. Natural language is full of idioms, metaphor and ambiguity unlike formal

language, misspelling and punctuations will have a big impact on the output. The interpreter did not understand the structure of the statement as such did not display the right result. 

1/(2/3) 1.5 The tokens are legal and are combined well in the arithmetic operation as such the interpreter displayed the right output.

Reference. Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press....


Similar Free PDFs