-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_challenge.py
More file actions
54 lines (36 loc) · 1.17 KB
/
input_challenge.py
File metadata and controls
54 lines (36 loc) · 1.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
# This challenge is only for Python 2.
# input()
# In Python 2, the expression input() is equivalent to eval(raw _input(prompt)).
# Code
# >>> input()
# 1+2
# 3
# >>> 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 k 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 4
# x**3 + x**2 + x + 1
# Sample Output
# True
# Explanation
# P(1) = 1 ^ 3 + 1 ^ 2 + 1 + 1 = 4 = k
# Hence, the output is True.
# Problem's link: https://www.hackerrank.com/challenges/input #
x, k = map(int, raw_input().strip().split())
polynomial = raw_input().strip()
polynomial = polynomial.replace('x', str(x))
print eval(polynomial) == k