Syntax error in spyder - invalid character in identifier

Upon following a program in below URL,

I get errors:

  1. NameError: name ‘cm’ is not defined

With some corrections from comments section, I used:
cm_gray = plt.get_cmap(‘gray’)

With corrections, I get:

  1. plt.imshow(im, cm_gray = plt.get_cmap(‘gray’))
    ^
    SyntaxError: invalid character in identifier

By removing ’ (single inverted comma), I get:

  1. plt.imshow(im, cm_gray = plt.get_cmap(gray))

NameError: name ‘gray’ is not defined

Kindly clarify.

I used: Spyder (Python 3.7)

always put full error message (starting at word “Traceback”) as text (not screenshot). There are other useful information.

Some times error can be in line before.

Some pages automatically use wrong ‘ ’ so you have to replace all of them with correct ' ' or " "

© Copyright 2013-2019 Analytics Vidhya