Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python只读取if语句,不读取任何elif语句_Python_Python 3.x - Fatal编程技术网

Python只读取if语句,不读取任何elif语句

Python只读取if语句,不读取任何elif语句,python,python-3.x,Python,Python 3.x,我正在用python开发一款老式的冒险游戏,当我运行move命令,将+1或-1添加到X或Y时,它不会检查elif语句 我在while True之后添加了一个print,发现代码只检查第一条语句是否为True,而不检查它下面的elif语句。我知道值会改变,但它不会用任何elif语句检查它们,它只检查if语句 while True: if X == "0" and Y == "0": inp = input('You are in a dark room and cannot

我正在用python开发一款老式的冒险游戏,当我运行move命令,将+1或-1添加到X或Y时,它不会检查elif语句

我在while True之后添加了一个print,发现代码只检查第一条语句是否为True,而不检查它下面的elif语句。我知道值会改变,但它不会用任何elif语句检查它们,它只检查if语句

while True:
    if X == "0" and Y == "0":
        inp = input('You are in a dark room and cannot see much. describe items, collect, move')
        if inp == "describe items":
            print('The room has a key, and two doors.')
        if inp == "collect":
            Icollect = input('Which item do you want to collect')
            if Icollect == "key":
                Slot = input('You have 5 inventory slots, which one do you want to put the key into?')
                Inventory[1] = 'key'
        if inp == "move":
            Move = input('Which door do you want to go through the door in front or to the right of you?')
            if Move == "front":
                Y = int(Y) + 1
            if Move == "right":
                X = int(X) + 1
    elif X == "0" and Y == "1":
        inp = input('You have climbed a set of stairs and entered what looks like a study. describe items, inspect, move')
        if inp == "describe items":
            print('There is a bookcase and a door to the left and behind you.')
        if inp == "inspect":
            inspect = input('You can only inspect the bookcase')
            if inspect == "bookcase":
                print('The bookcase has fallen and revealed a third door to your right')
        if inp == "move":
            Move = input('Which door do you want to go through the door to the left or behind you?')
            if Move == "behind":
                Y = int(Y) - 1
            if Move == "left":
                X = int(X) - 1
            if Move == "right":
                X = int(X) + 1
    elif X == "1" and Y == "0":
        inp = input('You went down a spiral staircase and entered a dungeon. describe items, collect, move')
        if inp == "describe items":
            print('The room has a key, and two doors.')
        if inp == "collect":
            Icollect = input('Which item do you want to collect')
            if Icollect == "key":
                Slot = input('You have 5 inventory slots, which one do you want to put the key into?')
                Inventory[1] = 'key'
        if inp == "move":
            Move = input('Which door do you want to go through the door in front or to the right of you?')
            if Move == "front":
                Y = int(Y) + 1
            if Move == "right":
                X = int(X) + 1

我希望代码会更改X和Y,然后会转到其他elif语句,因为这一条不再正确。代码更改了值,但它从未检查其他语句,只是检查了一条if语句。

如果我理解正确,您正在更改变量的类型

while True:
    if X == "0" and Y == "0":
        inp = input('You are in a dark room and cannot see much. describe items, collect, move')
        if inp == "describe items":
            print('The room has a key, and two doors.')
        if inp == "collect":
            Icollect = input('Which item do you want to collect')
            if Icollect == "key":
                Slot = input('You have 5 inventory slots, which one do you want to put the key into?')
                Inventory[1] = 'key'
        if inp == "move":
            Move = input('Which door do you want to go through the door in front or to the right of you?')
            if Move == "front":
                Y = int(Y) + 1
            if Move == "right":
                X = int(X) + 1
    elif X == "0" and Y == "1":
        inp = input('You have climbed a set of stairs and entered what looks like a study. describe items, inspect, move')
        if inp == "describe items":
            print('There is a bookcase and a door to the left and behind you.')
        if inp == "inspect":
            inspect = input('You can only inspect the bookcase')
            if inspect == "bookcase":
                print('The bookcase has fallen and revealed a third door to your right')
        if inp == "move":
            Move = input('Which door do you want to go through the door to the left or behind you?')
            if Move == "behind":
                Y = int(Y) - 1
            if Move == "left":
                X = int(X) - 1
            if Move == "right":
                X = int(X) + 1
    elif X == "1" and Y == "0":
        inp = input('You went down a spiral staircase and entered a dungeon. describe items, collect, move')
        if inp == "describe items":
            print('The room has a key, and two doors.')
        if inp == "collect":
            Icollect = input('Which item do you want to collect')
            if Icollect == "key":
                Slot = input('You have 5 inventory slots, which one do you want to put the key into?')
                Inventory[1] = 'key'
        if inp == "move":
            Move = input('Which door do you want to go through the door in front or to the right of you?')
            if Move == "front":
                Y = int(Y) + 1
            if Move == "right":
                X = int(X) + 1
X = "0"  
X = int(X) + 1
if X=="1":
   print("equals 1")
这是错误的,因为
类型(X)现在是int

或者生成
X
Y
int或字符串。不要把两者混为一谈,谢谢!我将字符串(X和Y)改为int,所以我不必使用int(Y)的东西,它就工作了。