
In this post we will discuss about how to make a code to add and remove the values from tuples using user-input method..
Code is Shown Below…
first make a tuple name as ” data “
data = ('Hat','Knee','Brush','Tail','Admin') # assign a tuple
now check the tuple working using print function
print(data) # used here to print the tuple name data
now use input function
Value = input("Want's to add/delete new item: ") # write "add" / 'delete'
now use if – else statement
if Value == 'add': # if user type "add" this will execute..
print('\n')
new_item = input("Enter New Item: ")
data.append(new_item)
print('\n')
print('Updated Value Tuple: ',data)
if Value == 'delete': # if user type 'delete' this will execute
print('\n')
value = input('Enter Item want to delete: ')
data.remove(value)
print('\n')
print('Updated Tuple: ',data)
else: # at last this executed
print('\n')
print('Thank You For Using the Code...!')
if you like the post drop a comment for support
regards from codershub…
Note :- If you wants to download a code go to “Working with codes” section from our website you will find all codes there in working conditions and update that codes accdording to you and send us for collabs…
Leave a Reply