0

So I have a dictionary

services = {
    "Waste Removal": 12.98,
    "Coffee Subscription": 32.99,
    "Lawn Mowing": 16.98,
    "Magazine Subscription": 21.98,
    "Cable TV": 23.98,
    "Music Subscription": 18.98,
}

I converted the dictionary into a list using services_list = list(Catalogue.services.keys())

I am then trying to remove elements from the list based on user input (Y/N). But the program is removing every element from the list and prints out the list line by line. Current output

 # Convert dictionary to a list.
services_list = list(Catalogue.services.keys())
# prompt for input
for i in services_list:
    opt = input("Opt out of " + i + " (Y/N) : ")
    if opt == "Y" or "y":
        services_list.remove(i)
        print(services_list)

This is what I am trying to achieve: expected output

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Bryan
  • 1
  • 1
  • 1
    BTW, welcome back to Stack Overflow! Check out the [tour] if you haven't already and [How to ask a good question](/help/how-to-ask) for tips. In the future, [please don't post pictures of text](https://meta.stackoverflow.com/q/285551/4518341). Instead, copy the text itself and use [code formatting](/editing-help#code) on it. – wjandrea Aug 04 '22 at 05:34
  • 1
    See also: [How do I do a case-insensitive string comparison?](/q/319426/4518341) – wjandrea Aug 04 '22 at 05:36

1 Answers1

2

Change up your if statement. Instead of doing if opt == "Y" or "y":, do if opt == "Y" or opt == "y":.