Pages

Saturday, December 31, 2016

Python-Interactive Mode and Script Mode

       In Python, there are two ways to code, one way in Interactive Mode and another way in Script Mode. While there are advantages to each both of them, there can be some disadvantages too, this is why you need to utilize both of them to be successful. The advantages to using Interactive mode is that you can test out bits of code to see if they work before you put them into your script. In script mode you can store multiple lines of code so that you can execute it all at once. There are also differences when you are coding in interactive mode and script mode that can also be confusing (Downey 17).
For example:

If you code this into the interactive mode then the output would show up under it
X=126
X*420






However if you type this exact code into script mode the output would be different


As you can see on the left side is the script, and when executed there was no output on the right, or the shell. This is because we didn’t tell Python to print out the output which is sometimes confusing as stated before. “But if you type the same code into a script and run it, you get no output at all. In script mode an expression, all by itself, has no visible effect. Python actually evaluates the expression, but it doesn’t display the value unless you tell it to:” (Downey 17).
  



Since we added the print command in the script there was a visible output like in the interactive mode.

Question: What are some other scenarios where you need more than one resource to be successful?

Downey, Allen B. Think Python: How to Think like a Computer Scientist. Sebastopol: O'Reilly Media, 2015. Print. 



0 comments:

Post a Comment