Answer to Question #293351 in Python for White

Question #293351

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
2022-02-02T17:31:40-0500

What happens if you miss one quotation or both in a string.

If you omit both quotations while outputting a string you get a name error. that is NameError: name is not defined. This is because the compiler will interprete the string as undefined word(s). If you omit one quotation, you get SyntaxError:EOL while scanning string literal error. This is because it will be hard to determine the end or the beginning of the string.

What Happens if you run the below Codes

2++2
  • the code above will run to give 4 as the result. this is because it is interpreted as 2+ (+2) which equal to 4.
2-2
  • the above code run to give 4 as the result. this is because it is interpreted as 2-(-2) and since - - =+ this will be executed as 2+2 which is 4.
2+-2
  • the code above run to give 0 as the result because it is interpreted as 2+(-2) and since + - = - this is the same as 2-2 which is 0
2-+2
  • the code above run to give 0 as the result since - + = - and therefore this is the same as 2-2 which is 0.


what happens if you use number with leading 0 in python

  • you will get SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers. this is because Python does not allow the use of leading zeros.


What happens If you have two numbers without an operator and with a space between them

  • you will get a syntax error. the error will be like; SyntaxError: invalid syntax

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