Computer Science, asked by shaikzafir8, 8 months ago

1. Write a python program to replace all 0s with a letter "x" in a tuple.

Answers

Answered by mad210203
0

Program is given below.

Explanation:

#Consider a tuple which contains numbers and zeros.

T = (0,1,2,3,4,0,0,5,2,9,11,66,0,123,78)

print("Before replacing: ")

print(T)

"""

A tuple is the collection of the objects which are ordered and immutable.

Once a tuple is created, we cannot change its values.

So, to change values in tuples, they should be converted into list and

then are converted back to tuple.

"""

y = list(T)

#Replacing 0s with a letter "x".

for n, i in enumerate(y):

if i == 0:

  y[n] = 'x'

#Again, converting list into the tuple.

T = tuple(y)

print("After replacing: ")

print(T)

Refer the attached image for the output.

Attachments:
Answered by anikethn
0

Answer:

l = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]

Explanation:

[(10, 20, 100), (40, 50, 100), (70, 80, 100)]

Similar questions