我目前正在开发DES实现,在代码的一部分中,我必须将数组追加到数组中,下面是我的代码:
C0=[1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1]
def Fiestel():
C=[]
C.append(C0)
temp=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]
C.append(temp)
print(C)
Fiestel()
Run Code Online (Sandbox Code Playgroud)
如何将数组附加到现有数组上,甚至尝试将C声明为2d数组。感谢您的帮助。
每个元素本身就是一个数组。
我是 Python 编程的新手,我正在尝试编写代码来检查 DFA(确定性有限自动机)是否具有空语言。
我正在使用二维数组来存储 DFA 的状态。在执行代码时,我不断让列表索引超出范围。我怎样才能解决这个问题?
下面是代码
top=-1
count=0
n=int(input("\nEnter the no of states"))
mat=[[]]
b=[]
print("\nEnter the transition table")
for i in range(0,n):
for j in range(0,n):
mat.append(input())
finalState=input("\nEnter the final state:")
startState=input("\nEnter the start state:")
for i in range(0,n):
for j in range(0,n):
if mat[i][j]:
b[++top]=j
for k in range(top):
if b[k]==finalState:
count+=1
if count>0:
print("\nLanguage is not empty")
else:
print("\nLanguage is empty")
Run Code Online (Sandbox Code Playgroud)