GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  • Python
  • Built-Ins
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

This view

  • Original page
  • New address

GeezerVison is showing www.hackerrank.com — Python Evaluation | HackerRank

We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

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

Author

shashank21j

Difficulty

Easy

Max Score

20

Submitted By

145418

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.