这个谜机器在python中出了什么问题?

时间:2012-07-17 10:23:00

标签: python

我已经准备好了自己设置制作一个谜机的挑战,这就是我到目前为止所做的事情,我已经去除了它并纠正了它。问题是代码很大,而且运行不正常。因为它出现了错误。 (我已经让它工作但没有正常工作。它应该知道运行正常但它没有) 如何缩短此代码? (所以我仍然可以在这个过程中学习) 代码没有运行的问题是什么?

背景:Enigma机器与轮子一起工作,当第一个轮子完成一个完整的旋转时,它会在每次用于第一个轮子时转动,它会回到开始状态,第二个轮子转一圈。等等,对于5个车轮。 (注意这段代码在末尾没有固定的位置,也没有你可以在代码末尾更改的位置)

import collections
import sys

wh1=input('wheel 1')
wh2=input('wheel 2')
wh3=input('wheel 3')
wh4=input('wheel 4')
wh5=input('wheel 5')
print'then enter the first letter'
theinput=raw_input('enter letter')
 # wheel 1
x=wh1

# wheel 2
y=[0] # the append list 
yy=wh2 # the value of rotation

# wheel 3
z=[0]
zz=wh3

# wheel 4
w=[0]
ww=wh4

# wheel 5
s=[0]
ss=wh5

# the values that are rotated
# note to add wh4ch to 5 to allow there to one for each wheel
wh1ch = collections.deque(['b','e','d','c','a'])
wh2ch = collections.deque(['d','a','b','e','c'])
wh3ch = collections.deque(['e','a','b','d','c'])
wh4ch = collections.deque(['a','b','c','d','e'])
wh5ch = collections.deque(['e','d','c','b','a'])




# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
    s=0













# wheel 1

if theinput == 'a':
    value=wh1ch[0]
    wh1ch.rotate(x)
    x= x+1

if theinput == 'b':
    value=wh1ch[1]
    wh1ch.rotate(x)
    x= x+1


if theinput == 'c':
    value=wh1ch[2]
    wh1ch.rotate(x)
    x= x+1

if theinput == 'd':
    value=wh1ch[3]
    wh1ch.rotate(x)
    x= x+1


if theinput == 'e':
    value=wh1ch[4]
    wh1ch.rotate(x)
    x= x+1
# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
    s=0




# wheel 2

if value == 'a':
    value=wh2ch[0]
    wh2ch.rotate(y[0])
    x= x+1

if value == 'b':
    value=wh2ch[1]
    wh2ch.rotate(y[0])
    x= x+1


if value == 'c':
    value=wh2ch[2]
    wh2ch.rotate(y[0])
    x= x+1

if value == 'd':
    value=wh2ch[3]
    wh2ch.rotate(y[0])
    x= x+1


if value == 'e':
    value=wh2ch[4]
    wh2ch.rotate(y[0])
    x= x+1
# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
    s=0
# wheel 3

if value == 'a':
    value=wh3ch[0]
    wh3ch.rotate(z[0])
    x= x+1

if value == 'b':
    value=wh3ch[1]
    wh3ch.rotate(z[0])
    x= x+1


if value == 'c':
    value=wh3ch[2]
    wh3ch.rotate(z[0])
    x= x+1

if value == 'd':
    value=wh3ch[3]
    wh3ch.rotate(z[0])
    x= x+1


if value == 'e':
    value=wh3ch[4]
    wh3ch.rotate(z[0])
    x= x+1

# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
    s=0


#wheel4

if value == 'a':
    value=wh4ch[0]
    wh4ch.rotate(w[0])
    x= x+1

if value == 'b':
    value=wh4ch[1]
    wh4ch.rotate(w[0])
    x= x+1


if value == 'c':
    value=wh4ch[2]
    wh4ch.rotate(w[0])
    x= x+1

if value == 'd':
    value=wh4ch[3]
    wh4ch.rotate(w[0])
    x= x+1


if value == 'e':
    value=wh4ch[4]
    wh4ch.rotate(w[0])
    x= x+1

# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
    s=0


# wheel 5

if value == 'a':
    value=wh5ch[0]
    wh5ch.rotate(s[0])
    x= x+1

if value == 'b':
    value=wh5ch[1]
    wh5ch.rotate(s[0])
    x= x+1


if value == 'c':
    value=wh5ch[2]
    wh5ch.rotate(s[0])
    x= x+1

if value == 'd':
    value=wh5ch[3]
    wh5ch.rotate(s[0])
    x= x+1


if value == 'e':
    value=wh5ch[4]
    wh5ch.rotate(s[0])
    x= x+1

# check1
if x>5:
    y.append(1)
    yy=y.count(1)
    x=0
# check2
if y>5:
    z.append(1)
    zz=z.count(1)
    y=0
# check3
if z>5:
    w.append(1)
    ww=w.count(1)
    z=0
#check4
if w>5:
    s.append(1)
    ss=s.count(1)
    w=0
#check5    
if s>5:
        s=0
#got to run a check function to equal out x in sections to make it neat do ( def check:
    # check functions for each list and lable the with hash #

    # do that for everything to make it neat 

print
print
print value
print 'these are the order of rotation of the coords of the wheels'
print x
print yy
print zz
print ww
print ss

0 个答案:

没有答案