Which version of Python?


#1

Hi, I wanted to put the Battleship code we learnt from Codecademy and play around with it on Pycharm. May I know which version of Python we're learning now on Codecademy?


#2

2.7.3 is the version of python codecademy uses. :slight_smile:


#3

Thank you very much!


#4

for battle ship there are two things you will need to tweak to make the code of the exercise work in pycharm (which i guess is python3), if so, all print statements require parentheses:

print("parentheses are required in python3")

and raw_input no longer exist, this is now input


#5

You'll only need to make a few slight changes to get the current version running in Python 3.

print "---"  becomes  print ("---")

print is now a function.

raw_input('...')  becomes  input('...')

raw_input is deprecated.

That should be all that needs changing, if I recall correctly.


#6

@stetim beat me to the punch. Leaving it anyway.


#7

Thank you all so much. I installed both versions on my computer and I think I'll try to redo it in Version 3. I seemed to also be having a problem with from random import randint, somehow it doesn't recognize this.


#8

Can't see why not, it works fine in IDLE.

>>> from random import randint
>>> randint(0,100)
54
>>>

Listed in the random module

https://docs.python.org/3/library/random.html


#9

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