在python程序崩溃中定义函数时

时间:2015-02-25 20:51:25

标签: python function user-defined-functions raw-input

显而易见,由于我明显缺乏编程经验而且相当新,学习速度慢,有人可以向我解释一下吗?该程序的其余部分运行良好独立于此部分,但我甚至不能单独运行此部分。 我有四个函数来声明和定义.x是一个字符r的位置是行号,c是列号。

def go_north():
    x = r - 1 
def go_south():
    x = r + 1
def go_west():
    x = c - 1
def go_east():
    x = c + 1

collumn = "c"
row= "r"

x = []
y = 0 
row =3
collumn =9
while (y < row):
    x.append ([])
    y= y +1

y = 0 
z = 0 
while(z < row): 
    y=0
    while(y < collumn): 
            x[z].append('*')
            y=y+1
    z=z+1
x[4][4] = "#"


raw_input ("")
    if "w" = go_north:
    else "s"= go_west:
    else "a"= go_east:
    elif "d"= go_west:

for y in x:
    print y

的raw_input( “”)

当我运行此代码的任何部分时程序崩溃,我无法找到我的问题。 我可以去寻找解决方案的任何提示或地点? (看起来很愚蠢,实际程序中的缩进是正确的)

1 个答案:

答案 0 :(得分:0)

这里有很多错误......

def go_north():
    x = r - 1 

def go_south():
    x = r + 1

def go_west():
    x = c - 1

def go_east():
    x = c + 1

input = raw_input ("")
if input == "w":
    go_north()
elif input == "s":
    go_west()
elif input == "a":
    go_east()
elif input == "d":
    go_west()

我建议阅读python语法

相关问题