You are on page 1of 1

Discussion Assignment Unit 1

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.

According to Downey (2015), “print('Hello, World!') This is an example of a print


statement,” (p.3).
Compare to this sample statement, a print statement obviously needs parentheses
before the value that we want to print. If we use Python 2, the parentheses are not
necessary because print is not a function in Python 2, whereas it is a function in
my version of Python 3. (Downey,2015).

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.

The third statement is type(1/2) and the output is


“In these results, the word “class” is used in the sense of a category; a type is a
category of
values” (Downey,2015).
After computing 1/2 , the result is 0.5 and it is a floating-point number.
Therefore, the output shows as .

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.

You might also like