Problem
This challenge is only for
Python 2
.
input()
In Python 2, the expression input() is equivalent to eval(raw _input(prompt)).
Code
>>> input() 1+23>>> company = 'HackerRank'>>> website = 'www.hackerrank.com'>>> input()'The company name: '+company+' and website: '+website'The company name: HackerRank and website: www.hackerrank.com'
Task
You are given a polynomial P of a single indeterminate (or variable), x.
You are also given the values of x and k. Your task is to verify if P(x) = k.
Constraints
All coefficients of polynomial P are integers.
x and y are also integers.
Input Format
The first line contains the space separated values of x and k.
The second line contains the polynomial P.
Output Format
Print True
if P(x) = k. Otherwise, print False
.
Sample Input
1 4x**3 + x**2 + x + 1
Sample Output
True
Explanation
P(1) = 13 + 12 +1 + 1 = 4 = k
Hence, the output is True
.
Solution – Input() In Python
x, k = list(map(int, input().split()))print(eval(input()) == k)
NOTE: The problem solved above, Input(), was generated by HackerRank and the solution was brought by the admin of CodingSolutions for educational purpose. Got any issues with the code? Ask your questions in the comment box and I shall attend to it.
Comments
Post a Comment