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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Built-Ins
  4. Input()
  5. Tutorial

Input()

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial
x = 2
print eval ('x+1')

Output of this code =

So , eval('expression') is used to evaluate an expression . It is used to find the value of the expression , given the values of all the variables involved in that expression.

input() and eval() perform the same task of evaluating an expression.

input() is equivalent to eval(raw_input()) . Let us see how :

For the given question the code using input() is as follows:

x,k = map ( int , raw_input().split())
print input() == k

And the code using eval( raw_input() ) is as follows:

x,k = map ( int , raw_input().split())
print eval(raw_input()) == k

The code using eval() is as follows :

x,k = map ( int , raw_input().split())
s= raw_input()
print eval(s) == k

tutorial details


Need Help?


View discussions
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy