Here is the code:
JavaScript
x
4
1
p1, p2 = eval(input("input the share price of two organizations: "))
2
if (p1>p2):
3
print("the first organization is performing better")
4
here is the error:
JavaScript
1
2
1
TypeError: eval() arg 1 must be a string, bytes or code object
2
Advertisement
Answer
Python’s eval()
allows you to evaluate arbitrary Python expressions from a string-based or compiled-code-based input. However, as the comments correctly say, this is best avoided.
All you need to do from here is convert strings
to integers
.
This would work better:
JavaScript
1
16
16
1
# get the inputs: p1, p2
2
b = input("input the share price of two organizations: ")
3
4
b = b.split(sep=',') # split the list into 2
5
6
# strip the white spaces
7
p1= b[0].strip()
8
p2= b[1].strip()
9
10
# convert to integers
11
p1, p2 = int(p1), int(p2)
12
13
# do some logic
14
if (p1>p2):
15
print("the first organization is performing better")
16