13 09 22 New Edited Tuple Program
13 09 22 New Edited Tuple Program
13 09 22 New Edited Tuple Program
1 Write a Python program to input 5 subject names and put it in a tuple and display
the tuple information on the output screen.
t=tuple()
for i in range(5):
a=(input("Enter 5 subject names : "))
t=t+(a,)
print("\nNames of 5 subjects are :",t)
Output :
T1=(1,3,5)
T2=(2,4,6)
tuple()
n=int(input("How many numbers to input : "))
for i in range(n):
a=int(input("Enter numbers : "))
t=t+(a,)
t1=t2=tuple()
for i in t:
if i%2==0:
t2=t2+(i,)
else:
t1=t1+(i,)
print("\nOriginal Tuple :",t)
print("\nFirst Tuple :",t1)
print("\nSecond Tuple :",t2)
3 Write a Python program to input n numbers and store in a tuple and find
minimum and maximum value from the tuple.
Or
Write a program to input ‘n’ employees’ salary and find
minimum & maximum salary among ‘n’ employees.
t=tuple()
for i in range(n):
t=t+(a,)
mn=min(t)
mx=max(t)
V1=(100,200,300,400,500)
V2=(15,250,120)
print("Tuple one : ",V1)
print("Tuple two :",V2)
V3=V1+V2
print("\n","Two tuple added : ",V3)
print("\n","The length of the added Tuple is : ")
print(len(V3))
5 Write a python program to Check if the given element is present in tuple or not.
6 Write a python program to concatenate the tuples using the ‘+’ operator.
Tuple1 = ("Hello", 6, 5, )
Tuple2 = (10.6, 25, "Python")
7 Write python code to create two tuples and interchange the tuple values .
T1,T2=T2,T1
t=tuple()
n=int(input("\nHow many numbers to enter : "))
print("Enter all numbers one after other")
for i in range(n):
a=input("enter number: ")
t=t+(a,)
print("\nThe entered numbers are :",t)
10
Write a Python program to clear Tuple elements
emptyTuple = tuple(vartup)
11 Write a Python program to output the following tuple elements using slicing
method.
# Ascending Sort
Tuple = (2, 3.5, 1, 6, 4)
print("\nSorted integer is:", sorted(Tuple))
Tuple1 = ('e', 'a', 'u', 'o', 'i')
print("\nSorted character is:", sorted(Tuple1))
# Descending Sort
aTuple = (2, 5, 8, 1, 9, 3, 7)
result = sorted(aTuple, reverse=True)
result = tuple(result)
print('\nSorted Tuple in descending order :', result)