-1

A generic trademark is what you get when a brand becomes so famous that people mistake it for the generic product.

One of the most famous examples is Velcro. The generic name is actually "hook and loop fastener". Much less catchy.

Write a program that can get rid of the brand names and replace them with the generic names.

The table below shows some brand names that have generic names. The mapping has also been provided to you in your program as the BRANDS dictionary.

BRANDS = {
  'Velcro': 'hook and loop fastener',
  'Kleenex': 'tissues',
  'Hoover': 'vacuum',
  'Bandaid': 'sticking plaster',
  'Thermos': 'vacuum flask',
  'Dumpster': 'garbage bin',
  'Rollerblade': 'inline skate',
  'Asprin': 'acetylsalicylic acid'
}

For this problem, you need to read in a sentence, and replace all brand names with the generic names like this:

Sentence: I bought some Velcro shoes. I bought some hook and loop fastener shoes. ​

Sentence: Time to Hoover the house. Time to vacuum the house. ​

It should remove all brands.

Sentence: Buy some Aspirin and Kleenex. Buy some acetylsalicylic acid and tissues.

I have tried this as my solution:

BRANDS = {
  'Velcro': 'hook and loop fastener',
  'Kleenex': 'tissues',
  'Hoover': 'vacuum',
  'Bandaid': 'sticking plaster',
  'Thermos': 'vacuum flask',
  'Dumpster': 'garbage bin',
  'Rollerblade': 'inline skate',
  'Asprin': 'acetylsalicylic acid'
}

sentence = input('Sentence: ')

for brand in BRANDS:
  sentence.replace(brand, BRANDS[brand])
print(sentence)

  • Please, format your codes to make your questions easier to read. – Felipe Augusto Sep 02 '18 at 03:15
  • `sentence = sentence.replace(brand, BRANDS[brand])` ... replace returns a new string – Joran Beasley Sep 02 '18 at 03:29
  • Welcome to stackoverflow, @NLynn. I trust you found the answer to your problem in the linked "duplicate" question. For the future, know that it makes a better impression if you make the effort to identify the *programming* task in your homework assignment (in this case: How to make multiple sequential string substitutions), and formulate your question around that. Brand names have nothing to do with the programming question here, but searching for "python multiple string substitutions" would have brought you to the solution and saved you the trouble of writing this question. – alexis Sep 02 '18 at 15:45

1 Answers1

0

Try this:

BRANDS = {
  'Velcro': 'hook and loop fastener',
  'Kleenex': 'tissues',
  'Hoover': 'vacuum',
  'Bandaid': 'sticking plaster',
  'Thermos': 'vacuum flask',
  'Dumpster': 'garbage bin',
  'Rollerblade': 'inline skate',
  'Aspirin': 'acetylsalicylic acid'
}

sentence = input("Sentence: ")
for brand in BRANDS:
    sentence = sentence.replace(brand, BRANDS[brand])
print(sentence)