今天python小白遇到一个小问题

x = input('please input months:')

months = set(['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'])

if x  in  months:
     print 'x:ok'
else:
    print 'x:error'

please input months:MON
Traceback (most recent call last):
  File "hello.py", line 119, in
    x = input('please input months:')
  File "", line 1, in

NameError: name 'MON' is not defined

终于找到问题的原因了2.7.14版本中要将input('please input months:')这里改成raw_input既可。

你可能感兴趣的:(今天python小白遇到一个小问题)