Algorithm


Problem Name: Python - Python Evaluation

Problem Link: https://www.hackerrank.com/challenges/python-eval/problem?isFullScreen=true

In this HackerRank Functions in PYTHON problem solution,

The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object.

For example:

>>> eval("9 + 5")
14
>>> x = 2
>>> eval("x + 3")
5

Here, eval() can also be used to work with Python keywords or defined functions and variables. These would normally be stored as strings.

For example:

>>> type(eval("len"))
<type 'builtin_function_or_method'>

Without eval()

>>> type("len")
<type 'str'>

Task
You are given an expression in a line. Read that line as a string variable, such as var, and print the result using eval(var).

NOTE: Python2 users, please import from __future__ import print_function.

Constraint
Input string is less than 100 characters.

Sample Input

print(2 + 3)

Sample Output

5

 

 

Code Examples

#1 Code Example with Python Programming

Code - Python Programming


var = input()
eval(var)
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
[Solved] Input() in PYTHON solution in Hackerrank
Next
[Solved] Any or All in PYTHON solution in Hackerrank