CLASS -11 COMPUTER SCIENCE
CHAPTER-2 PYTHON FUNDAMENTALS
Assignments
Type -A Questions :
1. What are tokens in Python ?How many types of tokens are allowed in Python ?
Ans . The smallest individual unit in a program is known as Token or Lexical unit.
There are 5 types of tokens in Python : 1) Keywords 2) Identifiers 3) Literals 4) operators 5) Punctuators
2. How are Keywords different from identifier ?
Ans . An identifier is the name used to store some variable value thus it has no special meaning in a program but a keyword is a word that has some special meaning in Python and cannot be used to store some value.
3 . What are Literals ? How many types of Literals are allowed in Python ?
Ans . Literals are data items that have a fixed value . The types of Literals allowed in Python are - 1)String Literal. 2) Numeric Literal 3) Boolean Literal 4)Special Literal "None" 5)Literal collection
4 . Can no graphic characters be used in Python ? Give example to support your answer.
Ans . Yes , we definitely can use nongraphic characters( those characters that can't be typed directly from keyboard ) in Python . Some of the nongraphic characters that are supported by Python are-
\\ It does the work of a backslash
\' It does the work of single quotes
\" It does the work of double quotes , etc.
5 .How are floating constants represented in Python ? Give example .
Ans . Floating constants are of two types 1) Fractional form 2) Exponential form .
The Fractional form is represented with decimal eg. .45 is represented as 0.45
The Exponential form is represented with the value raised after the letter ' E ' eg . 2² will be represented as 2 E2 .
6 .How are string Literals represented and implemented in Python ?
Ans . String Literals in Python is represented in single or double quotes . Their implementation in Python is that when we specify a string value to any variable we need to provide it in single or double quotes always . And if we want to convert any data type into string data type then we should use string( ) function .
7 .Which of these is not a legal Numeric type in Python ? a ) int b ) float c ) decimal .
Ans . c ) decimal
8 . Which argument of print( ) would you set for :
i ) changing the default separator (space) --> print (< to print > , end='<new separator >')
9 . What are operators ? What is their function ? Give example of some unary and binary operators .
Ans . Operators are tokens that trigger some operation on specified variables .
They are used to do some computaional operations (addition , subtraction , multiplication ,etc.) on variable .
Some of the unary operators are -
- unary plus (+)
- unary minus (-)
- bitwise complement (~)
- logical complement (not)
Some of the binary operators are -
- arithmetic operators ( + , - , * , etc. )
- bitwise operators ( & , ^ , | )
- shift operators ( << , >> )
- etc.
10 . What is an expression and a statement ?
Ans . An expression in any legal combination of symbols that represent certain value .
A statement is an instruction given in a program that does some work in program .
11 . What all components can a Python program contain ?
Ans . The various components of a Python program are - expression , statements , comments , function , block and indentation .
12 . What do you understand by block/code block/ suite in Python ?
Ans . A group of statements which are part of another statement or a function are called block/suite/block code .
13 . What is the role of indentation in Python ?
Ans . Indentations are the blank spaces that are provided before a code to create a block code .
14 . What are variables ? How are they important for a program ?
Ans . Variables are the name that stores some value in a program. They are important in a program because they are used to in almost every section of code from operating on them to printing in output .
15 . What do you understand by undefined variable in Python ?
Ans . Any variable which is not specified by any value in the program is called undefined variable in Python .
16 . What is dynamic typing feature in Python ?
Ans . Any variable pointing to a value can be made to point to some other value of different type in the same code . This facility is called dynamic typing in Python .
17 . What would the following code do : x=y=7
Ans . This code will make the variables x and y to point to integer 7 .
18. What is error in this code : x , y = 7
Ans . The error is that we need to provide one more value after 7 separating by ' , '.
19 . Following code is creating some problem X=0281 . Find the problem .
Ans . Here X=0281 will create problem because any number should not start with 0 but some other digit except it .
20 . " Comments are useful and easy way to enhance readability and understanndibility of a program . " Elaborate with examples .
Ans . Surely comments enable one to understand the code more easily .
Example -
a program to print the table of number 5 is as follows :
for I in range(1,11):
print(5*I)
#will print multiplication of 5and I
Here in this program the comment will acknowledge reader about the working of code and thus it becomes easy to understand the program.
Type B Application based questions :
Ans 1- b , d , f , g , h
Ans 2- underlined red coloured code are wrong👇🏻
i) temperature=90
print temperature
ii) a=30
b=a+b
print(a And b)
iii) a,b,c = 2,8,9
print(a,b,c)
c,b,a=a,b,c
print(a;b;c)
iv) x=24
4=X
v) print(''x=" x)
vi) else=21-5
Ans 3-
i) 15
13 , 22
ii) 2, 3, 6
11, 3, 33
iii) 7, 49
Ans 4-
i) Indentation error
ii) String + Integer concatenation error
iii) String Division with integer error
Ans 5- 20 , 41
Ans 6- 10 , 20
Ans 7- a) 12 , 6 , 24 b) 25
Ans 8- ''a , b , c : 10 , 20 , 30 "
''p , q , r : 25 , 13 , 16 "
Ans 9- a) value to X not provided b) assignment operation not allowed in print statement
c) String Division with integer error
Ans 10- Wrong input provided i.e. String not an integer
Ans 11- corrected code 👇:
name=input(''What is your name ? '")
print(''Hi", name , '','' ,end='' '')
print(''How are you doing ? '')
Ans 12- c = int(input(''Enter your class ''))
print('''Last year you were in class '', c-1)
Ans 13- a) integer b) integer c) error d) string e) float f) integer
g) float h) float i) float
Ans 14- a) One b) hello One
Ans 15- a ) b) Hola
Hola
Ans 16- It is so because Octal data type does not have integer 8 in its any representation .
Ans 17- 4 , 6 , 8
Ans 18- No, the id number will not be same for all values of n . It is so because the n is only a refering variable which refers to the different values assigned to it every time .
Ans 19- The error occurs because we are not allowed to assign value in print( ) function .
Ans 20- The amount of seconds 93784 .
👉MORE MATERIALS TO BE UPLOADED STAY TUNED👈