Python Tuples Challenges
# Question
1. Write a Python program to create and print the following tuple (' a', ' v', ' d')
Expected output:
(' a', ' v', ' d')
2. Write a Python program to get the 4th element from the beginning and 4th element
from the end of the following tuple : tuple_y = ('h','e','l','l','o','p','y','t','h','o','n')
Expected output:
l
t
3. Write a Python program to find the length of the following tuple.
tuple_x = (5, 10, 7, 4, 15, 3)
Expected output:
6
Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@[Link]
# Question
4. Write a Python program to define a new tuple from the tuple tu after repeating its
elements three times: tu = (' a', ' v', ' d'), using tuple repetition operator.
Expected output:
(' a', ' v', ' d', ' a', ' v', ' d', ' a', ' v', ' d')
5. Assume you have the tuples tu = (12, 30, 43, 22, -9, 4, 21, 44, 3), tu1 = ('a', ' v', ' d')
Write a Python program to:
a. Check whether the element 'a' exists in the tuple tu.
b. Find the maximum and minimum number in the tuple tu
c. Create a new copy of tu which contains tu, tu1 using tuple concatenation and
assign operator
d. Create a new tuple from tu, where it contains the last three elements of tu
Expected output:
a. False
b. 44
-9
c. (12, 30, 43, 22, -9, 4, 21, 44, 3, ' a', ' v', ' d')
d. (3, ' a', ' v')
To find out more about Python, web development, and data science visit us on:
Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@[Link]