Professional Documents
Culture Documents
In [1]: #Ql
#a)Empty Tuple
# defining an empty tuple
empty_tuple = ()
print(type(empty_tuple))
#b)Tuple having integer value
# defining a tuple with integer value
int_tuple = (1, 2, 3)
print(type(int_tuple))
#c)Tuple with mix data type
# defining a tuple with mixed data types
mix_tuple = (1, 'two', 3.0, False)
print(type(mix_tuple))
#d)Nested Tuple
# defining a nested tuple
nested_tuple = (1, 2, ('a', 'b', 'c'), 3)
print(type(nested_tuple))
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
In [2]: #Q2
tuple_name = ("Green", "Orange", "Blue")
new_tuple = tuple_name + ("Red",)
print(tuple_name)
( 'Green' , 'Orange' , 'Blue')
In [3]: #Q3
In [4]: #Q4
localhost:8889/nbconvert/html/Downloads/lDS/assignment2.ipynb?download=false 1/2
3/14/24, 2:04 PM assignment2
print(tuple[4:])
# To display 50 to 10
print(tuple[::-1])
(10, 20, 30)
(40, 'KIIT', 50)
( 30, 'BSC', 40, 'KIIT')
(50, 'KIIT', 40, 'BSC', 30, 20, 10)
In [5]: #Q5
students = [
{"Name": "John", "Mark": 90},
{"Name": "Emma", "Mark": 85},
{"Name": "Jim", "Mark": 95},
{"Name": "Jane", "Mark": 88},
{"Name": "Lucy", "Mark": 98}
In [6]: #Q6
n = 10
for 1 1n range(l, n+l):
print('(', i, ', ', i**2, ') ')
( 1 1 )
( 2 4 )
( 3 9 )
( 4 16 )
( 5 , 25 )
( 6 , 36 )
( 7 49 )
( 8 , 64 )
( 9 , 81 )
( 10 , 100
In [ ]:
2/2