0% found this document useful (0 votes)
10 views

Python Programming PRACTICAL NO.9 ANSWERS

The document outlines practical exercises for a Python programming course focused on tuple operations, including creation, access, printing, deletion, and conversion to lists. It also includes definitions, syntax examples, and comparisons between tuples and lists, along with sample programs to find minimum and maximum values, repeated items, and convert numbers into words. The content serves as a comprehensive guide for managing tuple data in Python.

Uploaded by

ARYAN MOHADE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Programming PRACTICAL NO.9 ANSWERS

The document outlines practical exercises for a Python programming course focused on tuple operations, including creation, access, printing, deletion, and conversion to lists. It also includes definitions, syntax examples, and comparisons between tuples and lists, along with sample programs to find minimum and maximum values, repeated items, and convert numbers into words. The content serves as a comprehensive guide for managing tuple data in Python.

Uploaded by

ARYAN MOHADE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

🌟 Diplomatech Academy 🌟

Manual Solutions and outputs


Python Programming Course Code: 314004
-Mohade Sir©

Practical No. 9: Write python program to perform following operations on


tuple:
Create, Access, Print, Delete & Convert tuple into list and vice-versa

ir
Ans.
eS
IX Conclusion:

We have successfully demonstrated various operations on tuples in Python. We


ad
learned how to create, access, print, and delete tuples and also how to convert a
tuple into a list and vice versa. Since tuples are immutable, conversion to lists
allows modification. These operations help in effectively managing tuple data in
Python programming.
oh
M

X Practical related questions

1) Define empty tuple. Write syntax to create empty tuple.


Ans.

Definition of an Empty Tuple


An empty tuple is a tuple that contains no elements. Tuples are immutable
sequences in Python.

Syntax to Create an Empty Tuple:

Method 1: Using Parentheses ()


empty_tuple = ()

Method 2: Using tuple() Constructor

ir
empty_tuple = tuple()

eS
2) Write syntax to copy specific elements existing tuple into new tuple.

Ans.
ad
Syntax to Copy Specific Elements from an Existing Tuple into a New Tuple

Method 1: Using Slicing ([:])


oh

old_tuple = (10, 20, 30, 40, 50)

new_tuple = old_tuple[1:4] # Copies elements from index 1 to 3

print(new_tuple) # Output: (20, 30, 40)


M

✅ Slicing is best for copying a range of elements.​


✅ Tuple comprehension allows filtering elements dynamically. 🚀

3) Compare tuple with list (Any 4 points).


Ans.

Difference Between Tuple and List

Feature Tuple List

Mutability Immutable (Cannot be Mutable (Can be modified)


changed)

ir
Syntax Defined using () Defined using []

ce
eS
Performan Faster (Due to
immutability)
Slower (Because of
modifications)
ad
Usage Used for fixed data storage Used for dynamic data
storage
oh

4) Create a tuple and find the minimum and maximum number from it.
M

Ans.

Python Program to Find the Minimum and Maximum Number in a Tuple

# Creating a tuple

numbers = (10, 25, 5, 40, 15)


# Finding minimum and maximum values

min_value = min(numbers)

max_value = max(numbers)

# Displaying the results

print("Minimum Number:", min_value)

ir
print("Maximum Number:", max_value)

eS
Output:

Minimum Number: 5
ad
Maximum Number: 40
oh
M

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

Ans.

Python Program to Find Repeated Items in a Tuple

# Creating a tuple with repeated elements

numbers = (1, 2, 3, 4, 2, 5, 3, 6, 3, 2)
# Finding repeated elements

repeated_items = {item for item in numbers if numbers.count(item) > 1}

# Displaying the result

print("Repeated items:", repeated_items)

ir
eS
Output:

Repeated items: {2, 3}


ad
6) Print the number in words for Example: 1234 => One Two Three Four

Ans.
oh

Python Program to Convert a Number into Words

# Dictionary mapping digits to words

num_to_words = {
M

'0': 'Zero', '1': 'One', '2': 'Two', '3': 'Three', '4': 'Four',

'5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight', '9': 'Nine'

# Function to convert number to words


def number_to_words(number):

return " ".join(num_to_words[digit] for digit in str(number))

# Input number

num = 1234

ir
# Convert and display result

eS
print("Number in Words:", number_to_words(num))

Output:

Number in Words: One Two Three Four


ad
oh
M

You might also like