Professional Documents
Culture Documents
Experiment No-2.4: Question - 1 Aim
Experiment No-2.4: Question - 1 Aim
4
NAME: Archit Sharma UID: 20BCS4862
SECTION/GROUP: 706/A4 SUBJECT: Python LAB
SEMESTER: 4th BRANCH: CSE
QUESTION- 1
AIM:
CODE:
#Python program to replace last value of tuples in a list
# Initializing list
test_list = [('gfg', 1), ('was', 2), ('best', 3)]
# Initializing N
N = 1
# printing result
print("The tuple after replacement is : " + str(res))
CODE SCREENSHOT:
OUTPUT SCREENSHOT:
QUESTION- 2
AIM:
CODE:
#Write a Python program to remove an empty tuple(s) from a list of
tuples
def Remove(tuples):
tuples = [t for t in tuples if t]
return tuples
# Driver Code
tuples = [(), ('ram','15','8'), (), ('laxman', 'sita'),
('krishna', 'akbar', '45'), ('',''),()]
print(Remove(tuples))
CODE SCREENSHOT:
OUTPUT SCREENSHOT:
QUESTION- 3
AIM:
Write a Python program calculate the product, multiplying all the numbers
of a given tuple.
CODE:
#Write a Python program calculate the product, multiplying all the
numbers of a given tuple.
def mutiple_tuple(nums):
temp = list(nums)
product = 1
for x in temp:
product *= x
return product
nums = (2, 4, 8, 8, 3, 2, 9)
print ("\nOriginal Tuple: ")
print(nums)
print("Product - multiplying all the numbers of the said
tuple:",mutiple_tuple(nums))
CODE SCREENSHOT:
OUTPUT SCREENSHOT:
QUESTION- 4
AIM:
CODE:
#Write a Python program to convert a tuple of string values to a tuple
of integer values
# initializing string
test_str = "(7, 8, 9)"
# printing original string
print("The original string is : " + test_str)
# printing result
print("The tuple after conversion is : " + str(res))
CODE SCREENSHOT:
OUTPUT SCREENSHOT:
QUESTION- 5
AIM:
CODE:
#Write a Python program to check if a specified element presents in a
tuple of tuples
def check_in_tuples(colors, c):
result = any(c in tu for tu in colors)
return result
colors = (
('Red', 'White', 'Blue'),
('Green', 'Pink', 'Purple'),
('Orange', 'Yellow', 'Lime'),
)
print("Original list:")
print(colors)
c1 = 'White'
print("\nCheck if",c1,"presenet in said tuple of tuples!")
print(check_in_tuples(colors, c1))
c1 = 'White'
print("\nCheck if",c1,"presenet in said tuple of tuples!")
print(check_in_tuples(colors, c1))
c1 = 'Olive'
print("\nCheck if",c1,"presenet in said tuple of tuples!")
print(check_in_tuples(colors, c1))
CODE SCREENSHOT:
OUTPUT SCREENSHOT:
Learning outcomes (What I have
statements.