Professional Documents
Culture Documents
For the statement “print ‘Hello, World!’ “, the output says “SyntaxError: Missing
parentheses in call to 'print'. Did you mean print(...)? “.
The output prints an error message because the syntax of the statement is
incorrect. Because of missing parentheses after print, the output does not show the
words, which is “Hello, World!”, as we expected.
For the statement “1/2”, the output is 0.5 because the statement has legal tokens
and correct syntax structure. The statement includes integer 1, operator /, and
integer 2, which means 1 divided by 2. The program computes mathematically and the
result is 0.5 as an output.
For the statement print(01), the output says “SyntaxError: leading zeros in decimal
integer literals are not permitted; use an 0o prefix for octal integers”.
The output shows syntax error because placing zeros before decimal integer literals
is illegal in Python.
For the last statement 1/(2/3), the output prints 0.5 as a result. Because of
adding parentheses, the program mathematically computes 2/3 first, then computes
the rest. Therefore, the result is correctly 0.5.
Finally, as a question, when I was trying to print a string, I wrote just the
string, like >>>’Hello, World!’, without writing print and parentheses. But the
program worked correctly and shows the string I wrote. Why did the program run
correctly by writing just the string?
Reference
Downey, A. (2015). Think Python: How to think like a computer scientist. Gree Tea
Press.