Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Name: Rais Saaim Ravish Enrollment No: 2105690153 Batch: 2

Copy specific elements existing tuple into new tuple

Syntax:

tuple = tuple

t1 = (10,20,30)
t2 = ()

t2 = t1

print("t1 = ",t1)
print("t2 = ",t2)

Output:

t1 = (10, 20, 30)


t2 = (10, 20, 30)

1. Create a tuple and find the minimum and maximum number from it

tup = (10,20,30,40)
print("Findin the Maximum and Minimum value")
print(tup)
print("Maximum number of the list is ", max(tup))
print("Minimum number of the list is", min(tup))

Output:

Finding the Maximum and Minimum value


(10, 20, 30, 40)
Maximum number of the list is 40
Minimum number of the list is 10

2. Write a Python program to find the repeated items of a tuple.

t1 = (10,20,10,20,1,2,3)
L = []
for i in t1:
if t1.count(i)>1:
if i not in L:
L.append(i)
print(L)

Output:

[10, 20]

3. Print the number in words for Example: 1234 => One Two Three Four
n =1234
n_words =''
while n > 0:
d = n% 10
if d == 0:
n_words = 'ZERO' + ' ' + n_words
elif d == 1:
n_words = 'ONE' + ' ' + n_words
elif d == 2:
n_words = 'TWO' + ' ' + n_words
elif d == 3:
n_words = 'THREE' + ' ' + n_words
elif d == 4:
n_words = 'FOUR' + ' ' + n_words
elif d == 5:
n_words = 'FIVE' + ' ' + n_words
elif d == 6:
n_words = 'SIX' + ' ' + n_words
elif d == 7:
n_words = 'SEVEN' + ' ' + n_words
elif d == 8:
n_words = 'EIGHT' + ' ' + n_words
elif d == 9:
n_words = 'NINE' + ' ' + n_words
else:
print('#')
n = n // 10
print(n_words)

Output:
ONE TWO THREE FOUR

You might also like