Answer to Question #292999 in Python for Phikem

Question #292999

Programming languages like Python are formal languages with strict syntax rules. But those rules can change over time with newer versions of the programming language. Your textbook covers Python 3, but you may only have access to Python 2.

Download and install a working Python environment, preferably Python 3, or get an account with 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.

>>> print 'Hello, World!'

>>> 1/2

>>> type(1/2)

>>> print(01)

>>> 1/(2/3)


1
Expert's answer
2022-02-01T23:55:24-0500

The codes have been run under python 3 environment

print 'Hello World!'

Output:

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
  • the above line of code returns a syntax error.
  • this is because print is a function and in python 3, a function should have parenthesis.
  • The above code should be written as print('Hello World!')
1/2

Output:

0.5


  • The line above will run perfectly to return the answer, 0.5, for division of 1 by 2
type(1/2)

Output:

float
  • the above code executes to return float.
  • This is correct since the division will return a decimal number (float datatype)
print(01)

Output:

SyntaxError: leading zeros in decimal integer literals are not permitted;
use an 0o prefix for octal integers
  • The above code returns a syntax error since in python 3, leading Zeros are not allowed with the integer literals.
1/(2/3)

Output:

1.5
  • The code above executes to return 1.5. The output is a float




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS