CS1101 DiscussionAssignmentU1
CS1101 DiscussionAssignmentU1
Download and install a working Python environment, preferably Python 3, or get an account with the
Virtual Computer Lab or PythonAnywhere. Refer to the Software Requirements/Installation section of
the course syllabus for details.
Type the statements below into your Python interpreter. For each statement, copy the output into your
Discussion Assignment and explain the output. Compare it with any similar examples in the textbook,
and describe what it means about your version of Python.
1/2
type(1/2)
print(01)
1/(2/3)
When you reply to your peers’ submissions, compare their results with yours.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C:\Users\user>python
Python 3.8.3 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
>>> 1/2
0.5
>>> type(1/2)
<class 'float'>
>>> print(01)
print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers
>>> 1/(2/3)
1.5
>>>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
This is a syntax error that takes place due to miss parentheses in the print function in python 3. When
we compare it with the similar example in the textbook, we find that in Python 3, the print statement is
a function, so it has to use parentheses. Otherwise, it doesn't use them because the print statement is
not a function in Python 2.
>>> ½
0.5
Explaining the output:
We use the operator / to perform division in Python, when we divide one by two, we get answer 0.5.
>>> type(1/2)
<class 'float'>
We use the type statement to get the category of value, so the value ½ is a floating-point number belong
to float.
>>> print(03)
print(03)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers
This is a syntax error that takes place when we use leading zeros in decimal integer literals, which are
not allowed; we do use 0o instead of just 0 to indicate octal integers in Python 3 but it doesn’t necessary
in Python 2.
>>> 1/(2/3)
1.5
The Python interpreter executes the arithmetic operator inside the parentheses first.