Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is calculator mode?

Tags:

python

I don't know about the meaning of calculator mode in Python, and I've put the portion of documentation below.

If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.

To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).

(Emphasis mine)

Here's the original document.

like image 532
wow yoo Avatar asked Aug 31 '16 03:08

wow yoo


People also ask

What is the normal mode for a scientific calculator?

Mode = 0; normal mode for performing normal arithmetic and function calculations.


1 Answers

Interactive mode and Calculator mode are the same thing. This is a mode that comes with Python. If you have installed Python then you have also installed something called the Python Shell.

There are two ways you can access the Python Shell:

  • Typing python or python[version-number] in your command prompt/terminal window:

    Assuming that you have python in your PATH variable, you can access the Python Shell by simply typing python or python[version-number] in your command prompt/terminal window.

  • Running the Python Shell in the Python IDLE(Integrated Development Environment) GUI:

    To run the Python Shell in the Python IDLE GUI, you can type(again i'm assuming that the path to your python installation folder, is in your PATH variable), just type idle into your command prompt\terminal window and this should start the Python Shell in the Python IDLE GUI.

Of course the exact text for the Python Shell heading will vary between OS's, but all of them look very similar. Here is an example of what the heading appears like on my Mac:

Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

As you can tell from the text above, a newline in the Python Shell is denoted by three caret symbols: >>>. For each newline three new carets are printed. Using Python Shell is different from typing a script because the script is predefined and the shell is written line-by-line.

Here is an example to illustrate my point further:

    >>> xyz = 100
    >>> for i in range(1, 10):
    ...     xyz += i
    ...     print(xyz)
    ... 
    101
    103
    106
    110
    115
    121
    128
    136
    145

As you can tell from the above program, indention is noted by three dots: ..., and the only time the Python Shell shows only one line at a time unless it is 'echoing' back what you typed in.

Why is it called interactive?

One of the main reason it's called interactive is that to display variable values or run the module in general you don't have to explicitly invoke the Python interpreter. Take the example below:

>>> name = "some name"
>>> print(name)
some name
>>> name
'some name'

As displayed above, you can access the values of a variable without needing to call print on the variable. This can be very useful when debugging or trying to understand your code.

The Python Shell is not really a practical way to write long/complex programs. A better choice would be to use the Python IDLE built-in script editor or another text-editor or IDE.

like image 136
Christian Dean Avatar answered Sep 20 '22 13:09

Christian Dean