Create a tuple having squares of the elements from the list

In this python tuple program, we will create a tuple having squares of the elements from the list.

Steps to solve the program
  1. Create a tuple and convert it to a list using list().
  2. Use for loop to iterate over elements in the list.
  3. Find the index of the element using index().
  4. Get the square of the element.
  5. Now replace the square with the old element in the list.
  6. Now convert that list to a tuple using tuple().
  7. Print the output.
				
					tup = (1,3,5,7,6)
print("Origianl tuple: ",tup)
a = list()
for i in list(tup):
    b = i**2
    a.append(b)
tup = tuple(a)
print("After sqauring elements: ",tup)
				
			

Output :

				
					Origianl tuple:  (1, 3, 5, 7, 6)
After sqauring elements:  (1, 9, 25, 49, 36)
				
			

multiply adjacent elements of a tuple.

1 thought on “Create a tuple having squares of the elements from the list”

Leave a Comment