0% found this document useful (0 votes)
12 views2 pages

Python Tuple Challenges and Solutions

This document provides 5 Python tuple challenges to test tuple skills. The challenges include: 1) Creating and printing a tuple, 2) Accessing elements from the beginning and end of a tuple, 3) Finding the length of a tuple, 4) Repeating tuple elements using repetition operator, and 5) Checking for tuple elements, finding max/min, concatenating tuples, and slicing the last elements. The expected outputs are provided for each challenge.

Uploaded by

Michael Leone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Python Tuple Challenges and Solutions

This document provides 5 Python tuple challenges to test tuple skills. The challenges include: 1) Creating and printing a tuple, 2) Accessing elements from the beginning and end of a tuple, 3) Finding the length of a tuple, 4) Repeating tuple elements using repetition operator, and 5) Checking for tuple elements, finding max/min, concatenating tuples, and slicing the last elements. The expected outputs are provided for each challenge.

Uploaded by

Michael Leone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]

You might also like