Class 12 CS Chapter 1 Python Revision Tour I Solutions — PYTHON TUTORIAL 2021

Python Programming
4 min readApr 8, 2021

Class 12 CS Chapter 1 Python Revision Tour I

Class 12 CS Chapter 1 Python Revision Tour I Solutions

Q 1. What is the difference between a keyword and an identifier ?

Ans. Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are a few. For example, if, elif, else etc. are keywords.

Identifier is the user-defined name given to part of a program viz. variable, object, function etc. Identifiers are not reserved. These are defined by the user but they can have letters, digits and a symbol underscore. They must begin with either a letter or underscore. For instance, _chk, chess, trial etc. are identifiers in Python.

Q 2. What are literals in Python ? How many types of literals are allowed in Python ?

Ans. Literals mean constants i.e., the data items that never change their value during a program run. Python allow five types of literals :
(i) string literals
(ii) Numeric literals
(iii) Boolean literals
(iv) Special Literal None
(v) Literal Collections like tuples, lists etc.

Q 3. How many ways are there in Python to represent an integer literal ? (Python Revision Tour I)

Ans. Python allows three types of integer literal :

(a) Decimal (base 10) integer literals

An integer literal consisting of a sequence of digits is taken to be decimal integer literal unless it begins with 0 (digit zero)

For instance, 1234, 41, +97, -17 are decimal integer literals.

(b) Octal (base 10) integer literals

A sequence of digits starting with 0 (digit zero) is taken to be an octal integer.

For instance, decimal integer 8 will be written as 010 as octal integer.

and decimal integer 12 be written as 014 as octal integer

© Hexadecimal (base 16) integer literals

A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer.
Dor instance, decimal 12 will be written as 0XC as hexadecimal integer.
Thus number 12 will be written either as 12 (as decimal), 014 (as octal) and 0XC (as hexadecimal).

Q 4. How many types of strings are supported in Python ?

Ans. Python allows two string types :
(i) Single line Strings Strings that are terminated in single line
(ii) Multiline Strings Strings storing multiple lines of text.

Q 5. What is None literal in Python ?

Ans. Python has one special literal called None.
The None literal is used to indicate something that has not yet been created. It is a legal empty value in Python.

Q 6. The following code is not giving desired output. We want to input value as 20 and obtain output as 40. Could you pinpoint the problem ?

Number = input("Enter Number") DoubleTheNumber = Number*2 print(DoubleTheNumber)

Ans. The problem is that input( ) returns value as a sting, so the input value 20 is returned string ‘20’ and not as integer 20. So the output is 2020 in place of required output 40.
Also Print is not legal statement of Python; it should be print.

Q 7. Why is following code giving errors ?

name = "Rehman" print("Greetings !!!" print("Hello", name) print("How do you do ?")

Ans. The problem with above code is inconsistent indentation. In Python, we cannot indent a statement unless it is inside a suite and we can indent only as much as required.
Thus, corrected code will be :

name = "Rehman" print("Greetings !!!" print("Hello", name) print("How do you do ?")

Q 8. What are data types ? What are Python’s built-in core data types ?

Ans. The real life data is of many types. So to represent various types of real-life data, programming languages provide ways and facilities to handle these, which are known as data types.
Python’s built-in core data types belong to :

  • Numbers (integer, floating-point, complex numbers, Boolean’s)
  • String
  • List
  • Dictionary
  • Tuple

Q 9. Which data types of Python handle Numbers ?

Ans. Python provides following data types of handle numbers (version 3.x) :
(i) Plain integers
(ii) Long integers
(iii) Boolean
(iv) Floating-point numbers
(v) Complex numbers

Q 10. Why is Boolean considered a sub-type of integers ? (Python Revision Tour I)

Ans. Boolean values True and False internally map to integers 1 and 0. That is, internally True is considered equal to 1 and False as equal to 0 (zero). When 1 and 0 are converted to Boolean through bool( ) function, they return True and False. That is why Boolean are treated as a subtype of integers.

read more

Originally published at https://kamalsinghstarbooks.xyz.

--

--