Im working on the code the finding the maximum evaluation (ignoring precedence) such as
我正在编写代码,以找到最大的评估(忽略优先级),比如。
2
2
5+ 3*2
5 + 3 * 2
-1 + -4 * -3
-1 + -4 * -3。
Output
输出
16
16
40000000000
40000000000
I have the following code which returns the following error:
我有以下代码返回以下错误:
ValueError: invalid literal for int() with base 10: '-' m[i][i] = int(d[i]) File
Note: I have looked through the other questions with a similar error, but this is different from each of them. Im using Python 3and it docent work.
注意:我已经通过类似的错误查看了其他的问题,但是这与他们的不同。我使用的是Python 3和它的工作。
def get_maximum_value(expression):
expression="".join(expression.split())
op = expression[1:len(expression):2]
d = expression[0:len(expression)+1:2]
n = len(d)
m = [[0 for i in range(n)] for j in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
m[i][i] = int(d[i])
M[i][i] = int(d[i])
for s in range(1,n):
for i in range(n-s):
j = i + s
m[i][j], M[i][j] = MaxValue(i,j,op,m,M)
return M[0][n-1]
num=int(input())
for i in range(num):
expression=input()
print (get_maximum_value(expression))
However, it shows ValueError: invalid literal for int() with base 10: '-' m[i][i] = int(d[i])
.
然而,它显示了ValueError:以10为基数的int()的字面量无效。
I tried to change the int to float but it still doesnt work.
我试着把int改为float,但它仍然不工作。
1 个解决方案
#1
0
There is a similar question asked here and I found the answer by SethMMorton useful by using a function to force conversation of float numbers in string type directly to int. Give it a try.
这里也有一个类似的问题,我发现SethMMorton的答案是有用的,它使用一个函数来强制把浮点数的会话直接插入到int中,试试吧。
#1
0
There is a similar question asked here and I found the answer by SethMMorton useful by using a function to force conversation of float numbers in string type directly to int. Give it a try.
这里也有一个类似的问题,我发现SethMMorton的答案是有用的,它使用一个函数来强制把浮点数的会话直接插入到int中,试试吧。