Hi I have a python code which does the following things sequentially
- Displays a list of urls
- asks the user if they want to remove any links.
- If the user inputs yes then takes an input which link to remove and removes the link
- code exits.
My issue is I want the code to ask the user again after removing the link if they want to remove more links?
Can someone help me figure it out. Sorry I am new to python so if this question seems very trivial.
My code:
import sys
def remove_links():
# initializing list
list = links
# initializing string
str_to_remove = input("Enter the link you want to remove: ")
# Remove List elements containing String character
# Using list comprehension
links.remove(str_to_remove)
# printing result
print("The list after removal : " + str(links))
print(len(links))
# printing original list
print("The list of links are : " + str(links))
print(len(links))
# Sets to simplify if/else in determining correct answers.
yesChoice = ['yes', 'y']
noChoice = ['no', 'n']
# Convert their input to lowercase.
choice = input("Do you want to remove some/any links? (y/N) ").lower()
if choice in yesChoice:
remove_links()
elif choice in noChoice:
# exit the code
sys.exit("User doesn't want to make any modifications.")
else:
# print("Invalid input.\nExiting.")
sys.exit("Invalid input.\nExiting.")