Calculator in Python

Calculator

In python calculator is at primary prompt. Just write any expression and you get the answer.

  • Numbers: do the following a primary command prompt.

Figure 1.1.1 Calculator

So, you have an inbuilt calculator, we can write complex expression, it is always better to enclose them in parenthesis. See example below:

1.1.2 Expressions

A division operator always leaves the result as float. So 5/2=2.5

Whereas a floor operator (//) discard the fraction part, so 10/3= 3

Other operators are +, -, *, /, %, //, **, =

In python last printed expression is assigned to variablele _

 

Example-1 Example-2

>>> x,y= 10,5

>>>z= x*y

>>>w=_ + 5

>>>w

55

 

Note that now z =x*y to _ and add 5 to it to get 10*5 + 5 = 55

 

>>> tax = 12.5 / 100

>> >price = 100.50

>>>price * tax12.5625

>>> price + _113.0625

round(_, 2)113.06

 

 

Updated: June 10, 2019 — 3:12 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

care4you © 2014 care4you © Revision-1: 2016 care4you © Revision-2: 2019 Connect On Facebook DMCA.com Protection Status
error: Content is protected !!