Getting Started: Python and IDLE Exercise results

In the instructions to installing Python and IDEL, the document ends with some exercises. I thought I’d post my results here. It all looks ok, though I can’t check the final answer easily. What did you get?

>>> 4+4
8
>>> 6+4*10
46
>>> (6+4)*10
100
>>> 23^5
18
>>> import math
>>> (-68+math.sqrt(68*68-4*34*-510))/(2*34)
3.0

Thanks for posting that. However 23 to the power of 5 is written as 23**5 in Python, and it’s 6436343, not 18. Not sure what the caret sign indicates in Python, but it is something other than power. That’s confusing because it is used that way in some other languages.

1 Like

Hi there,
I self-started learning Python a week ago or so by following some videos and installing v3.4.3
So I’m going to push it (if you dont mind) and see what happens.
First difference i’ve seen is that the Python -V command doesn’t seem to work.
The exercises results are these:

    Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
    >>> 4+4
    8
    >>> 6+4*10
    46
    >>> (6+4)*10
    100
    >>> 23**5
    6436343
    >>> import math
    >>> (-68+math.sqrt(68*68-4*34*-510))/(2*34)
    3.0

Cheers.

The caret ^ is a bitwise exclusive OR operator in Python, and is covered during the latter portion of the Codecademy exercises. It does not seem likely that it would play a major role in the MOOC.

Some of the other differences between Python versions 2 and 3 are …

  • print is a command in version 2, and a function in version 3. So in version 3, the values to be output must be enclosed in parentheses.

  • To prompt for and collect user input, with version 2 you should use the raw_input function, while in version 3, you need to use the input function.

  • The / division operator performs floating point division in version 3, while in version 2, the type of division depends upon the types of the operands.

If you attempt to do the MMOOC with version 3, you may, at first, find that it is easy to adapt the code between the two Python versions, but as the course proceeds, adaptation will become increasingly complex. For the three projects in the final weeks of the course, it would take a huge amount of work to adapt them to version 3, because they use existing code modules that are written for version 2. So, imo, it seems advisable to do the entire MMOOC in version 2. I have IDLE 2 and 3 on the same machine, and it has caused no problem.

1 Like

Zed Shaw gets really mad when someone queries him about Python 3. And he has especially advised beginners against using Idle…Hee, hee…But seriously, you should check out his “Learn Python the Hard Way” site, i am just too lazy to finish anything, that’s why i am here, Idle it is for me. :relaxed: