Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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 3初学者_Python_Python 3.x - Fatal编程技术网

Python 3初学者

Python 3初学者,python,python-3.x,Python,Python 3.x,我目前正在尝试让这个小代码工作。当我执行它时,唯一发生的事情是cmd提示说按enter键关闭。如何让脚本的其余部分运行和显示?我在上学的初级班。这不需要过于简化。在大多数情况下,只有3个房间,我需要能够在3个房间之间来回移动,仅此而已 # A dictionary for the simplified dragon text game # The dictionary links a room to other rooms. rooms = { 'Great Hall': {'South

我目前正在尝试让这个小代码工作。当我执行它时,唯一发生的事情是cmd提示说按enter键关闭。如何让脚本的其余部分运行和显示?我在上学的初级班。这不需要过于简化。在大多数情况下,只有3个房间,我需要能够在3个房间之间来回移动,仅此而已

# A dictionary for the simplified dragon text game
# The dictionary links a room to other rooms.
rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
}


def movebetweenrooms(player, direction):
    """
    Returns the new player state after moving into another room
    """

    current_room = player

    # check if there is a room in the specified direction
    if direction in rooms[current_room]:
        current_room = rooms[current_room][direction]

    # error handling
    else:
        print("There is nothing in that direction!")

    # return the player state
        return current_room


def displayinstructions():
    """
    display the starting instructions
    """

    print("Simplified Dragon Text Game\n\n"
          "Collect 6 items to win the game, or be killed by the Dragon.\n"
          "Move commands: go South, go North, go East, go West\n")


def main():
    displayinstructions()
    player = ("Great Hall", [])

    while True:

        current_room = player

        # Player info
        # -----------
        print(f"\nYou are in the {current_room}")

        # Game ending
        # -----------
        if player[0] == "Cellar":

            if len(player[1]) == 0:
                print(f"Congratulations! You have defeated the Dragon!")
            else:
                print("NOM NOM...GAME OVER!")

            # greeting and exiting
            print("Thanks for playing the game. Hope you enjoyed it.")
            break

        # input validation and parsing
        # ----------------------------
        # get the player's move
        print("-" * 35)
        move = input("Enter your move:\n")

        # invalid move syntax
        if " " not in move:
            print("Invalid input!")
            continue

        # split the move into an action and an argument
        action, arg = move.split(" ", 1)

        # move into another room
        if action == "go":
            movebetweenrooms(player, arg)

        # invalid action
        else:
            print("Invalid input!")


input('Press ENTER to exit')

python中不会自动执行
main
函数

如果希望它运行,请在脚本末尾添加以下内容:

如果uuuu name_uuuu=='\uuuuuuu main\uuuuuu':
main()

请使用您的问题标题来描述您遇到的问题或您提出的问题。初学者是不相关的,从您添加的标记中可以清楚地看到python 3。你的标题应该足够清晰和描述性,以便将来的网站用户扫描搜索结果列表,试图找到解决问题的方法。谢谢。请同时阅读,和,并把你的代码压缩成一个。欢迎来到堆栈溢出!在哪里调用
main()
?如果你不打电话,你认为会发生什么事吗?非常感谢。