Answer to Question #179933 in Python for FORTUNE AIDOO

Question #179933

1.      >>> 2- 2



2.      >>> 2 -(2-)

 File "<stdin>", line 1

   2 -(2-)

         ^

SyntaxError: invalid syntax


3.      >>> (0+1)-9(1/2)

<stdin>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>

TypeError: 'int' object is not callable


Give explanation to these results experimented in python above.

1
Expert's answer
2021-04-10T01:13:37-0400
  1. There is no error because the syntax is correct. This is a correct way to find 2 minus 2.
  2. We can put expressions in parentheses when we want to give the highest priority to some operation in the expression. Here, in parentheses we have '2-'. The minus operator is expecting the next number to subtract but instead there is nothing. That is why '2-' is invalid expression and we got syntax error.
  3. If we want to multiply 9 by 1/2, we need to write 9*(1/2). Otherwise, 9(1/2), without *, is accepted like a function because it is python way to call functions ('function()'). For this reason, we have type error ('int' object is not callable).

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