Using Python as calculator
Python has the very large number of libraries and each library has its own specific use. But before heading towards advance Python, we must be knowing the basics of it.
What you have to do is to simply open your Python Console in pycharm and we are all set to go.In the Python Console as well as in our examples , input and output are distinguished by the presence or absence of prompts (>>> and …): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with the prompt are output from terminal .And we will be giving comments with #. Click here to know more about comments.
Now, open your python console and wait for the prompt(>>> ) to appear.(It must not take too long to appear)
eg.
#Some basic operations
>>> 67+89 ↵ #Input
156 #Output
>>> (659+567)/(456-345)*6 ↵
66.27027027027027 # Output Can also generate floating point output
# Now using /, // and % operators.
>>> 17/10 ↵ # simple division operation
1.7
>>> 17//10 ↵ # // returns floor value(discard fractional part)
1
>>> 17%10 ↵ # // return remainder
7
# Now using ** operators.
>>> 17**2 ↵ # return power of a number
1.7
# You can also give floating point numbers(Decimal numbers) as input .
>>> 18.0/2.0 ↵ # return floating point number
9.0
# You can also store numbers in a variable and then perform the same operations.
>>> a=2.0 ↵ # assign 2.0 to a
>>> b=3.0 ↵ # assign 3.0 to b
>>> a**b ↵ # calculating a to the power b
8.0 # Output
# We can also do above operations in this way:
>>> a=2.0 ↵ # assign 2.0 to a
>>> b=3.0 ↵ # assign 3.0 to b
>>> c=a**b ↵ # calculating a to the power b
>>> c ↵
>>> 8.0 # Output
# An error will occur if you try to access undefined variables
>>> k
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'k' is not defined
# We can also use floating point and integer number together
>>> 8.0/3
2.6666666666665
NOTE: Remember that we cannot use ++ or -- operators in python as they are not supported and when used throw an error
Comments
Post a Comment
Please do not enter any spam link in the comment box