programjilo.blogg.se

Python console calculator
Python console calculator






In the second case, 10 divided by 5 is 2 with no remainder, so the modulo is 0. In this case, 10 divided by 3 is 3 remainder 1, so the modulo is 1.

python console calculator

The modulo operator (represented by %) finds the remainder when one number is divided by another: > 10 % 3 1 > 10 % 5 0 You can use brackets to change this, just like in regular maths. Python uses * for multiply and / for divide, similar to most other programming languages (and spreadsheets).īy default, multiply and divide take precedence over add and subtract. These are some simple additions and subtractions. In each case, type in the bold text and you should see Python print the answer (shown in italics). Simple maths in PythonĪs you might have guessed, when you type in something like 3 + 2 in the IDLE console window, Python evaluates it and displays the answer, 5. Here, you have typed in 10 * 3 (10 multiplied by 3) followed by a return, and Python has replied with 30. So, a complete transaction might look like this: > 10 * 3 30 Don't type in the >, that is just the prompt Python displays! We will show Python's response in italics, like this: 5 This means that you should type 3 + 2 into the window, and hit return. We will show this in bold, like this: > 3 + 2 You can type instructions into this window. The version of Python is displayed in the title bar and the initial message on the screen. Search for the IDLE program in the program finder (eg Start Menu in Windows, Dash in Ubuntu). You should have already seen this in the first lesson.

python console calculator

Python comes with a simple, built-in user interface called IDLE.

python console calculator

If not, follow the instructions in the Introduction lesson. You should already have Python installed on your computer. This is a good way to get to know some of the basic things Python can do before we move on to do some real programming. In this lesson, we will use the IDLE program to interact with Python directly.








Python console calculator