-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_evaluation.py
More file actions
41 lines (28 loc) · 1007 Bytes
/
python_evaluation.py
File metadata and controls
41 lines (28 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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
# Problem's link: https://www.hackerrank.com/challenges/python-eval #
from __future__ import print_function
expression = raw_input().strip()
eval(expression)