gpt4 book ai didi

python - 无效语法错误 : Quine McCluskey Algorithm in python

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:36:31 24 4
gpt4 key购买 nike

我是 python 的新手,这是我 friend 发给我的一些代码,这是 Quine-McCluskey 算法,它提供了获取最小项的答案,代码在某种程度上很简单,但因为我不是经验丰富的 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 - 无效语法错误 : Quine McCluskey Algorithm in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56926580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com