PWP SOLVED INTERNAL v2
PWP SOLVED INTERNAL v2
t1 = (a,)
t2 = (b,)
t1, t2 = t2, t1
print("First tuple:", t1)
print("Second tuple:", t2)
OR
t1 = (1, 2, 3)
t2 = ('a', 'b', 'c')
t1, t2 = t2, t1
print("First tuple:", t1)
print("Second tuple:", t2)
OR
class NegativeNumberError(Exception):
pass
try:
num = int(input("Enter a number: "))
if num < 0:
raise NegativeNumberError("Negative numbers are not allowed!")
print("The number is:", num)
except NegativeNumberError as e:
print(e)
if string == string[::-1]:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
largest = max(numbers)
smallest = min(numbers)
def read_student_info(self):
self.name = input("Enter student's name: ")
self.roll_no = input("Enter student's roll number: ")
self.department = input("Enter student's department: ")
self.mobile_no = input("Enter student's mobile number: ")
def print_student_info(self):
print("Student Information:")
print("Name:", self.name)
print("Roll No:", self.roll_no)
print("Department:", self.department)
print("Mobile No:", self.mobile_no)
# Parent class
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print(f"{self.name} makes a sound.")
dog = Dog("Buddy")
cat = Cat("Whiskers")
dog.speak()
cat.speak()
rows = 4
for i in range(rows):
print(" " * i, end="")
for j in range(rows - i):
if j % 2 == 0:
print("1", end=" ")
else:
print("0", end=" ")
print()
11) Write python program to perform following operations on
set.
i) Create set of five elements
ii) Access set elements
iii) Update set by adding one element
iv) Remove one element from set.
# i) Create set of five elements
my_set = {1, 2, 3, 4, 5}
# ii) Access set elements
print("Set elements:")
for element in my_set:
print(element)
# iii) Update set by adding one element
my_set.add(6)
print("Set after adding 6:", my_set)
# iv) Remove one element from set
my_set.remove(3)
print("Set after removing 3:", my_set)
Output:
Google 1
Facebook 2
Microsoft 2
GFG 1
Youtube 3
14) Write the output for the following if the variable course =
“Python”
>>> course [ : 3 ]
>>> course [ 3 : ]
>>> course [ 2 : 2 ]
>>> course [ : ]
>>> course [ -1 ]
>>> course [ 1 ]
Output:
Pyt
hon
Python
n
y
import numpy as np
class InvalidPasswordException(Exception):
pass
def check_password(input_password):
correct_password = "mypassword123"
if input_password != correct_password:
raise InvalidPasswordException("Password is incorrect!")
else:
print("Password is correct!")
17) Write the output for the following if the variable fruit =
‘banana’.
>> fruit [:3]
>> fruit [3:]
>> fruit [3:3]
>> fruit [:]
Output:
ban
ana
banana
Output:
SPAM!
SPAM!
('SPAM!', 'SaPm')
['spam', 'Spam', 'SPAM!', 'SaPm']