Discussion Forum Uni1
Discussion Forum Uni1
The output is an error message indicating a syntax error. The above print statement works in Python
2.x and not in Python 3.x
In my version of Python which is Python 3.9.5 I need to add the parentheses so that it indicates that
“Print” is a function hence printing the value.
>>> 1/2
0.5
Here, the output is clear which is a floating-point (Downey, A., 2015). Because the statement we
typed is an arithmetic operation with a correct syntax and token which is an arithmetic operator.
>>> type(1/2)
<class 'float'>
The output indicates the word “class” which is the category of the value inside the parentheses
because the statement above is a Python type function and has a correct syntax and token.
>>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers
The above print statement returned an error message indicating a syntax error because leading zeros
are not allowed in python 3.x
P.S. I did a research and found out that in order to display leading zero in Python Python 3.+ you can
use print("{:02d}".format(1)) (Stack Overflow, 2008).
>>> 1/(2/3)
1.5
The output is a value of 1.5 which is a floating-point number. The output was fine because my
version of Python is 3.x while in Python 2.x it returned an error. For my version of Python, it means
an arithmetic operation with a correct syntax and tokens.
References
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
Jack, M. (2008, September 25). Display number with leading zeros. Stack Overflow.
https://stackoverflow.com/questions/134934/display-number-with-leading-zeros
In the last reference, the author didn’t write his full name so I found an issue citing this reference.