PWP QB Answers
PWP QB Answers
1) Enlist any 4 features of python.
Ans: Features of Python are:(any 4)
1. Easy to code
2. Free and Open source
3. Object Oriented Language
4. GUI Programming language
5. High level language
6. Portable Language
7. Interpreted Language
8. Large Standard Library
9. Dynamically Typed Language
10.Integrated Language
Membership operator:
● Membership operators check whether a value is in another.
● Python has 2 membership operators:
1. In: Returns True if a sequence with the specified value is present in
the object.
2. Not in: Returns True if a sequence with the specified value is not
present in the object.
Example:
Identity operator:
● Identity operators check whether two values are identical.
● Python has 2 identity operators as well::
1. Is: checks if two operands refer to the same object in memory,
returning True if they are the same, and False otherwise.
2. Is not: The is not operator in Python checks if two operands do not
refer to the same object in memory, returning True if they are
different, and False if they are the same.
Example:
9) Explain if else ladder.
Ans:
List Dictionary
12) Write the output for the following if the variable course="Programming"
>>>course[:4]
Prog
>>>course[2:]
ogramning
>>>course[2:3]
o
>>>course[-1]
g
4 mark Questions:
1) Write a program that takes a number and checks whether it is palindrome.
number = int(input("Enter a number: "))
original_number = number
reversed_number = 0
while number > 0:
digit = number % 10
reversed_number = (reversed_number * 10) + digit
number //= 10
if original_number == reversed_number:
print(original_number, "is a palindrome.")
else:
print(original_number, "is not a palindrome.")
OR
#Union
U = S1|S2
print ("Union = ", U)
#Intersection
I = S1&S2
print ("Intersection = ", I)
#Difference
D = S1-S2
print ("Difference = ", D)
#Symmetric Difference
S = S1^S2
print ("Symmetric Difference= ", S)
Output : -
Union = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Intersection = {2, 5, 7}
Difference = {1, 3, 4, 6}
Symmetric Difference= {1, 3, 4, 6, 8, 9, 10}
#remove elements
set1.remove(10)
print("Set after removing:", set1)
7) Write a program to create a dictionary of students that includes their roll no and
name.
1. Add 4 students in the above dictionary.
2. Update name= "Priya" of roll no 2
3. Delete info of roll no=1
4. Print only keys then values and data in key:value pair.
# 4. Print only keys, then values, and finally data in key:value pair
t1=[3,4,6,10,5,9]
O/P: #it will create a list t1, which is a list of integers
print(t1[1])
O/P: 4
print(t1[-1])
O/P: 9
print(t1[3:])
O/P: [10, 5, 9]
print(t1[:])
O/P: [3, 4, 6, 10, 5, 9]