我在Python中是全新的,这里有一些代码是我朋友发给我的,这是Quine McCluskey Algorithm,它提供了解决问题的方法,代码很简单,但是因为我不是Python程序员,所以我没有太多的想法来解决这个问题。
这是源代码:Quine-McCluskey (github)

def find_minimum_cost(Chart, unchecked):
P_final = []
#essential_prime = list with terms with only one 1 (Essential Prime Implicants)
essential_prime = find_prime(Chart)
essential_prime = remove_redundant_list(essential_prime)

#print out the essential primes
if len(essential_prime)>0:
    s = "\nEssential Prime Implicants :\n"
    for i in range(len(unchecked)):
        for j in essential_prime:
            if j == i:
                s= s+binary_to_letter(unchecked[i])+' , '
    print s[:(len(s)-3)] #ERROR  <--------

#modifiy the chart to exclude the covered terms
for i in range(len(essential_prime)):
    for col in range(len(Chart[0])):
        if Chart[essential_prime[i]][col] == 1:
            for row in range(len(Chart)):
                Chart[row][col] = 0

-
File "C:\Users\Lenovo\Desktop\main.py", line 204
  print s[:(len(s)-3)]
        ^
SyntaxError: invalid syntax

错误在这行:print s[:(len(s)-3)]

最佳答案

最初的作者打算用python2解释器执行程序。
他(粗略地)写道:

print s

要使用现代python3解释器执行,您需要:
print(s)

关于python - 无效的语法错误:Python中的Quine McCluskey算法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56926580/

10-11 12:21