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

Py_ass_4

Uploaded by

venkatakalyan2nd
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)
2 views

Py_ass_4

Uploaded by

venkatakalyan2nd
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
You are on page 1/ 3

Python Assignment -4

Name: Gaduputi Venkata Kalyan

1. Create a tuple 'fruits' containing '("apple", "banana", "cherry")'.


Access and print the second element of the tuple.

2. Given the tuple 'numbers = (1, 2, 3, 4, 5)', use slicing to print the
subtuple '(2, 3, 4)’.

3. Create a tuple 'colors' with the elements '("red", "green", "blue")'.


Use the '.index()' method to nd the index of "green" and print the
result.
fi
4. Given the tuple 'values = (1, 2, 3, 1, 2, 1)', use the '.count()' method
to count how many times 1 appears in the tuple and print the result.

5. Create a tuple 'person' containing '("John", 25, "Engineer")'. Unpack


the tuple into three variables 'name', 'age', and 'profession', and print
each variable.

6. Given the tuple 'numbers = (1, 2, 3, 4, 5)', convert it to a list, append


the number 6, and then convert it back to a tuple. Print the nal tuple.

7. Create a tuple 'dimensions' containing '(1920, 1080)'. Use tuple


unpacking to assign the values to variables 'width' and 'height', then
print 'width' and ‘height'.
fi
8. Given the tuple 'data = (10, 20, 30, 40, 50)', create a new tuple
'even_data' that contains only the even numbers from 'data' using a
generator expression, and print ‘even_data'.

9. Create a tuple 'letters' with the elements '('a', 'b', 'c', 'd')'. Convert
the tuple to a string by joining the elements with a comma separator
and print the resulting string.

10. Given the tuple 'records = ((1, "Alice"), (2, "Bob"), (3, "Charlie"))',
iterate over the tuple and print each ID and name on a new line.

You might also like