0% found this document useful (0 votes)
3 views5 pages

Python Tuples Assignment

This document outlines a Python Tuples assignment for students, consisting of 25 questions divided into beginner, intermediate, and advanced levels. It includes tasks such as creating tuples, accessing elements, performing operations like counting and sorting, and developing a menu-driven utility program. Additionally, there are bonus challenges and instructions for writing clean code and submitting the assignment.

Uploaded by

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

Python Tuples Assignment

This document outlines a Python Tuples assignment for students, consisting of 25 questions divided into beginner, intermediate, and advanced levels. It includes tasks such as creating tuples, accessing elements, performing operations like counting and sorting, and developing a menu-driven utility program. Additionally, there are bonus challenges and instructions for writing clean code and submitting the assignment.

Uploaded by

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

Python Tuples Assignment

Beginner to Advanced (25 Questions)


Student Name: ______________________
Class: ______________________
Date: ______________________

Python Tuples Assignment


Beginner Level (Questions 1–10)
1.
Create a tuple containing the names of five fruits and print it.

2.
Create a tuple of five numbers and print the first and last elements.

3.
Write a program to find the length of a tuple.

4.
Access and print each element of a tuple using indexing.

5.
Use positive and negative indexing to access different elements of a tuple.

6.
Write a program to print the first four elements of a tuple using slicing.

7.
Print the last three elements of a tuple using negative slicing.

8.
Create a tuple with different data types (integer, float, string, boolean) and
print each element along with its data type.
9.
Write a program to check whether a given element exists in a tuple.

10.
Create a tuple with a single element and print it. Explain why a comma is
required in a single-element tuple.

Intermediate Level (Questions 11–18)


11.
Write a program to count how many times a given element appears in a
tuple.

12.
Write a program to find the index of a given element in a tuple.

13.
Create two tuples and concatenate them into one tuple.

14.
Repeat a tuple three times using the repetition operator and print the result.

15.
Write a program to find the maximum and minimum values in a tuple of
numbers.

16.
Write a program to calculate the sum and average of all elements in a
numeric tuple.

17.
Convert a tuple into a list, add a new element, and convert it back into a
tuple.

18.
Write a program to sort the elements of a tuple in ascending order.
Advanced Level (Questions 19–25)
19.
Write a program to remove duplicate elements from a tuple.

20.
Write a program to merge two tuples and remove duplicate values.

21.
Create a nested tuple containing student details (Name, Roll Number, Marks)
for five students and display the information in a formatted manner.

22.
Write a program to unpack the following tuple into separate variables:
student = ("Rahul", 101, "BCA", 8.7)

23.
Write a program to swap the values of two variables using tuple unpacking
without using a third variable.

24.
Write a program to find the second largest element in a tuple.

25.
Create a menu-driven Tuple Utility Program that allows the user to
perform the following operations:
 Display the tuple
 Find the length of the tuple
 Search an element
 Count the occurrences of an element
 Find the index of an element
 Find the maximum and minimum values
 Calculate the sum and average (for numeric tuples)
 Convert the tuple to a list and add a new element
 Exit
Bonus Challenge (Optional)
1.
Write a program to check whether all elements in a tuple are unique.

2.
Create a tuple of 20 random numbers and count how many are even and
how many are odd.

3.
Write a program to flatten a nested tuple into a single tuple.

4.
Write a program to compare two tuples and check whether they contain the
same elements (regardless of order).

5.
Create a tuple containing employee details (ID, Name, Department, Salary)
and allow the user to search for an employee by ID.

Practice on Built-in Tuple Functions and Methods


Write separate Python programs demonstrating the use of the following:

Tuple Methods
1. count()
2. index()
Built-in Functions
3. len()
4. max()
5. min()
6. sum()
7. sorted()
8. tuple()
9. list()
10. enumerate()
11. any()
12. all()
13. reversed()
14. zip()

Instructions
 Write clean and properly indented Python code.
 Use meaningful variable names.
 Add comments where necessary.
 Test your programs with different inputs.
 Submit all solutions in a single Python file ( tuple_assignment.py).

You might also like