-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTuple_P12.py
More file actions
42 lines (34 loc) · 1.04 KB
/
Tuple_P12.py
File metadata and controls
42 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
l = [ ]
t = ( )
print("\n\t\t\tTuple")
print("\t\t\t------")
print("1. Create")
print("2. Length")
print("3. Concatenate")
print("4. Delete")
print("5. Exit")
while True:
c = int(input("\nEnter the choice: "))
if c == 1:
n = int(input("Enter the number of elements: "))
l=[ ]# Clear the list before creating new list
t=( ) # Clear the tuple before creating new tuple
for i in range(n):
e = int(input("Enter the element: "))
l.append(e)
t=t+tuple(l)
print("Tuple: ", t)
elif c == 2:
print("Number of elements in tuple: ", len(t))
elif c == 3:
up = int(input("Enter the element to append: "))
t = t + (up,) # Append the new element as a single-element tuple
print("Tuple: ", t)
elif c == 4:
del t # Reset the tuple instead of deleting
print("Tuple deleted")
elif c == 5:
print("Exiting...")
break
else:
print("Enter the option between 1-5")