Answer to Question #179562 in Python for FORTUNE AIDOO

Question #179562

Include example Python code and output with your answers.

  • If you are trying to print a string, what happens if you leave out one of the quotation marks or both and why?
  • You can use a minus sign to make a negative number like -2. What happens for each of the following and why?

>>> 2++2

>>> 2--2

>>> 2+-2

>>> 2-+2

  • In math notation, leading zeros are OK, as in 02. What happens if you try this in Python and why?
  • What happens if you have two values with no operator and a space in between them and why?
1
Expert's answer
2021-04-08T17:19:34-0400
print(2++2)  # 2 + (+2) = 4
print(2--2) # 2 - (-2) = 4
print(2+-2) # 2 + (-2) = 0
print(2-+2) # 2 - (+2) = 0


if you have two values without an operator and a space between them, then python will throw the SyntaxError: invalid syntax error

if you omit the quotation mark, you will get the SyntaxError: EOL while scanning string literal error, because it is not possible to determine the beginning or end of the string

python does not allow leading zeros, there will be a SyntaxError error: leading zeros in decimal integer literals are not allowed; use the 0o prefix for octal integers


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

Aletha Teta Karpeh
27.01.22, 13:15

Thank you for the clue

Nana
07.09.21, 13:28

Thanks a lot,this was very helpful

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS