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

2024-10-03 06:18:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经为自己设定了一个制造谜机的挑战,这就是我迄今为止所做的,我已经把它除掉并修正了它。问题是代码量很大,而且不能正确运行。因为它带来了一个错误。)我已经开始工作了,但还没有正常工作。它应该知道运行正常,但它没有) 我怎样才能缩短代码?(这样我还能在这个过程中学习) 代码不运行的问题是什么?在

背景:谜之谜机器与轮子一起工作,当第一个轮子完成一个完整的旋转时,它会回到开始,第二个轮子转动一圈。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

Tags: theifvaluecountwheelprintrotateappend