Difficulty with Python syntax


#1

So I am learning Python with Codecademy and I also downloaded Anaconda Navigator with the Spyder IDE, I currently am using Spyder (Python 3.6).

I am experiencing some differences in syntax, for example it doesn’t like raw_input() rather it takes input() and the print function requires (). I want to eventually learn Python for programming my new raspberry pi 3 model B. I like Codecademy because its great practice! However it might be a little tricky transferring my knowledge of the language over to the raspberry pi later. Any suggestions… I might be wrong and maybe I can use 3.5 or a different version. Any thoughts??

It keeps throwing me the following error:

(NameError: name ‘new_word’ is not defined) on the following code.

pyg = 'ay'

original = input('Enter a word:')
if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  new_word = word[1:len(new_word)] + first + pyg
  #print original
##the above was used to check the code meanwhile we created the new_word
  print (new_word)
else:
  print (empty)

#2

This is done in two steps if we follow the instructions correctly.

empty is undefined. This should be a string, "empty".


#3

It is fine to learn Python 2 on Codecademy, then adapt your knowledge to Python 3 for the Raspberry Pi. Most of what your learn will still apply. Regarding the main differences, see What’s New In Python 3.0.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.