Basic Calculator in Just One Line Using Python
- In this program we will learn how to write a code basic calculator in just one line using python.
- eval() function is one of my favorite function in python.
- It evaluate the string as python expression and return as an integer
Syntax :
- eval(expression, globals=None, locals=None)
Eval Function :
- The Function evaluates the "String" like a python expression and returns the result as integer.
Source Code:
#Follow @Programmerfect
print(eval("18+16"))
print(eval("18-16"))
print(eval("18*16"))
print(eval("18/16"))
print(eval("18-16+20"))
print(eval("18-16+20*4"))
print(eval("18**16-5"))
print(eval("18-16*45-100+36**2"))
print(eval("18+16"))
print(eval("18-16"))
print(eval("18*16"))
print(eval("18/16"))
print(eval("18-16+20"))
print(eval("18-16+20*4"))
print(eval("18**16-5"))
print(eval("18-16*45-100+36**2"))