0

This is my code.

amazon = 'https://www.amazon.in/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=%s'

prime = 'https://www.primevideo.com/search/ref=atv_nb_sr?phrase=%s&ie=UTF8'

if 'amazon' in query:

speak('What product shall I search for?')

amz_product = take Command().lower()

webbrowser.get(chrome_path).open(amazon%amz_product)

elif 'prime video' in query:

speak('What shall I play on prime')

prime_movie = takeCommand().lower()

webbrowser.get(chrome_path).open(prime%prime_movie)

Getting error as "ValueError: unsupported format character 'D' (0x44) at index 59". This is for 'amazon' variable. For 'prime' variable, the code is working fine.

Not sure as how to fix the extra '%' symbol in snippet 'search-alias%3Daps' in the link defined in 'amazon' variable.

Please let me know if you need more info over this. Any help would be appreciable. Thank you!!!

  • If you're going to use `%`-formatting in your string, you need to double any actual `%` characters in the string to escape them. You might want to look into using the `.format()` method, which is considered more modern, and has no problem with `%`s (but requires special handling for curly braces, instead). – jasonharper Feb 25 '21 at 22:33
  • Can you please guide me on how to use the `.format()` for the code snippet provided above for 'amazon' variable. Unable to figure it out. It'll be of great help. – aklavya mishra Feb 26 '21 at 00:05

0 Answers0