0% found this document useful (0 votes)
20 views1 page

Discussion Forum Uni1

The document shows Python code examples and their outputs. It demonstrates print statements and arithmetic operations in Python 3.9.5, showing both correct and incorrect syntax. It also discusses displaying numbers with leading zeros in Python.

Uploaded by

Safa Hamaizia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Discussion Forum Uni1

The document shows Python code examples and their outputs. It demonstrates print statements and arithmetic operations in Python 3.9.5, showing both correct and incorrect syntax. It also discusses displaying numbers with leading zeros in Python.

Uploaded by

Safa Hamaizia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Hello everyone! I used Python 3.9.

>>> print 'Hello World!


SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello World!)?

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.

You might also like