0% found this document useful (0 votes)
2 views

PWP Question Bank Class test 1[1]

The document is a question bank for a Python class test covering various topics such as features of Python, loop control statements, decision-making statements, set operations, and basic programming constructs. It includes questions on Python syntax, data structures, and programming examples. Additionally, it discusses the differences between lists and tuples, membership operators, and the importance of indentation in Python.

Uploaded by

Samiksha Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PWP Question Bank Class test 1[1]

The document is a question bank for a Python class test covering various topics such as features of Python, loop control statements, decision-making statements, set operations, and basic programming constructs. It includes questions on Python syntax, data structures, and programming examples. Additionally, it discusses the differences between lists and tuples, membership operators, and the importance of indentation in Python.

Uploaded by

Samiksha Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PWP QUESTION BANK FOR CLASS TEST 1(24-25)

1) Write the features of Python?


Ans.
 Easy to Learn and Use
 Interactive Mode
 Expressive Language
 Interpreted Language
 Cross-platform Language
 Portable
 Free and Open Source
 Object-Oriented Language
 Extensible
 Large Standard Library
 GUI Programming Support
 Integrated
 Databases
 Scalable

2) What happen if a semicolon (;) is placed at the end of a Python statement?


3) Write the different loop control (manipulation) statements available in Python?
Explain with suitable examples

4) Explain decision making statements If- else, if- elif- else with example.
Ans. The if-else statement: if statements executes when the conditions following if is true and it
does nothing when the condition is false. The if-else statement takes care of a true as well as
false condition.
Syntax-1: If condition: Or
Statement(s) Syntax-2: If condition:
else: If_Block
Statement(s) else:
else_Block

Example: i=20
if(i<15):
print(" less than 15")
else:
print("greater than 15")
output:
greater than 15
if-elif-else (ladder) statements: Here, a user can decide among multiple options. The if
statements are executed from the top down. As soon as one of the conditions controlling the if is
true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If
none of the conditions is true, then the final else statement will be executed.
Syntax: if (condition-1):
statement
elif (condition-2):
statements
.
.
elif(condition-n):
statements
else:
statements

Example:
i = 20
if (i == 10):
print ("i is 10")
elif (i == 15):
print ("i is 15")
elif (i == 20):
print ("i is 20")
else:
print ("i is not present")
output: i is 20

5) Write the output for the following if the variable fruit=’banana’:


>>>fruit [:3]
>>>fruit [3:]
>>>fruit [3:3]
>>>fruit [:]
Ans.

6) Write the output of the following:


i) >>> a = [1,2,3]
>>> b = [ 4,5,6]
>>>c=a+b
ii) >>> [1,2,3] *3
Ans.

7)Write in brief about Set in Python. Write operations with suitable examples.
Answer: A Set is an unordered collection data type that is iterable, mutable and has no duplicate
elements. Python’s set class represents the mathematical notion of a set. The major advantage of
using a set, as opposed to a list, is that it has a highly optimized method for checking whether a
specific element is contained in the set. This is based on a data structure known as a hash table.
If Multiple values are present at the same index position, then the value is appended to that index
position, to form a Linked List. In, Python Sets are implemented using dictionary with dummy
variables, where key beings the members set with greater optimizations to the time complexity.
Set = set(["a", "b", "c"])
print("Set: ")
print(Set)
# Adding element to the set
Set.add("d")
print("\nSet after adding: ")
print(Set)
Output:
Set:
set(['a', 'c', 'b'])
Set after adding:
set(['a', 'c', 'b', 'd'])

8)Write s python code to get the following dictionary as output:


{1:1,3:9,5:25,7:49,9:81}
9) What is list? How to create list?
10)Write a python program for following output
*
**
***
****
*****
Ans. n = int(input("Enter the number of rows you want to print?"))
i,j=0,0
for i in range(0,n):
print()
for j in range(0,i+1):
print("*",end="")

11)Name different modes of python.


Ans. Python has two basic modes:
• Script (Normal Mode)
• Interactive Mode

12)List different conditional statements in Python


Ans.
13)Describe membership operator in python
Ans, Membership Operators: The membership operators in Python are used to find the existence
of a particular element in the sequence, and used only with sequences like string, tuple, list,
dictionary etc. Membership operators are used to check an item or an element that is part of a
string, a list or a tuple. A membership operator reduces the effort of searching an element in the
list. Python provides ‘in’ and ‘not in’ operators which are called membership operators and used
to test whether a value or variable is in a sequence.
Sr. No Operator Description Example

1 in True if value is found in >>> x="Hello World" >>>


list or in sequence, and print('H' in x) True
false it item is not in list or
in sequence
2 not in True if value is not found >>> x="Hello World" >>>
in list or in sequence, and print("Hello" not in x)
false it item is in list or in False
sequence.

14)What is role of indentation in python.


Ans. Indentation refers to the spaces at the beginning of a code line. Python indentation refers to
adding white space before a statement to a particular block of code. In another word, all the
statements with the same space to the right, belong to the same code block.

15)Describe multiline comment in python.


Ans. Multi line comment: Python multi-line comment is a piece of text enclosed in a delimiter
(""") Triple quotation marks.
Example: """
Multi-line comment used
print("Python Comments") """
or
To add a multiline comment you could insert a # for each line:
Example:
#This is a comment
#written in
#more than just one line print("Hello, World!")

16)Write a python program to calculate sum of digit of given number using function.
17)List building blocks of python.
Ans.
Character set: All characters that python can recognize. The below table illustrates the Python
character set along with examples.
Tokens: Tokens in python are building blocks of the Python programming language. The role
letters and words play for the English language, Similar to role token play for a python
programming language.
Python has the following tokens:
1)keywords
2)identifiers
3)literals : a)String literals b)Numeric literals c)Boolean Literals d)Special literal None

Tokens, Example
Keywords: Words that are already defined False, True, if, elif, else, for, while, pass,
and convey a special meaning to the language continue, lambda return, finally, import, def
compiler/interpreter
Identifiers: names given to different parts of def square, num=20, a_lst=[1,2,3]; here
program like variables, functions, object, square, num and a_lst are identifiers.
class, names given to different datatypes.
Literals/Constants: Data items that have fixed String: ‘Mayank‘,’abc‘,’anish‘; Numeric:
values 1,1.2,4,-3.95; Boolean: True,False
Special literal None; meaning nothing

18)Give differences between list and Tuple.


List Tuple
Lists are mutable Tuples are immutable
Lists consume more memory Tuple consume less memory as compared to
the list
Lists have several built-in methods Tuple does not have many built-in methods.
The unexpected changes and errors are more In tuple, it is hard to take place.
likely to occur
The List has the variable length. The tuple has the fixed length
List operations are more error prone. Tuples operations are safe
Lists can be used to store homogeneous and Tuples are used to store only heterogeneous
heterogeneous elements. elements.
List is useful for insertion and deletion Tuple is useful for readonly operations like
operations. accessing elements
List iteration is slower and is time consuming. Tuple iteration is faster.

You might also like