Computer Science

From the following, find out which assignment statement will produce an error. State reason(s) too.

(a) x = 55
(b) y = 037
(c) z = 0o98
(d) 56thnumber = 3300
(e) length = 450.17
(f) !Taylor = 'Instant'
(g) this variable = 87.E02
(h) float = .17E - 03
(i) FLOAT = 0.17E - 03

Python Funda

90 Likes

Answer

  1. y = 037 (option b) will give an error as decimal integer literal cannot start with a 0.
  2. z = 0o98 (option c) will give an error as 0o98 is an octal integer literal due to the 0o prefix and 8 & 9 are invalid digits in an octal number.
  3. 56thnumber = 3300 (option d) will give an error as 56thnumber is an invalid identifier because it starts with a digit.
  4. !Taylor = 'Instant' (option f) will give an error as !Taylor is an invalid identifier because it contains the special character !.
  5. this variable = 87.E02 (option g) will give an error due to the space present between this and variable. Identifiers cannot contain any space.
  6. float = .17E - 03 (option h) will give an error due to the spaces present in exponent part (E - 03). A very important point to note here is that float is NOT a KEYWORD in Python. The statement float = .17E-03 will execute successfully without any errors in Python.
  7. FLOAT = 0.17E - 03 (option i) will give an error due to the spaces present in exponent part (E - 03).

Answered By

35 Likes


Related Questions