python - 文本冒险中匹配用户选择的问题。

标签 python python-2.7 text-based adventure

我目前正在使用 python 进行简单的文本冒险。基本上我希望 randint 选择 1 或 2,然后分配给 right_wire,然后 raw_input 为 wire_choice,然后匹配 2 以提供所需的结果。我相信你们无论如何都能弄清楚我在这里想做什么。我离这里很近还是真的很远?谢谢!

    right_wire = randint(1, 2)

    wrong_wire = 0

    if right_wire == 1:
        wrong_wire = 2
    elif right_wire == 2:
        wrong_wire = 1
    else:
        print "ERROR"

    while True:
        print "Which wire do you pull?"
        print
        print "1. The red one."
        print "2. The blue one."
        print
        wire_choice = raw_input('*>>*')

        if wire_choice == 1 and right_wire == 1:
            print "**BOMB DEFUSED**"
            return 'engineering2'
        elif wire_choice == 2 and right_wire == 2:
            print "**BOMB DEFUSED**"
            return 'engineering2'
        elif wire_choice == 1 and right_wire == 2:
            print "**FAILED**"
            return 'death'
        elif wire_choice == 2 and right_wire ==1:
            print "**FAILED**"
            return 'death'
        else:
            print no_understand

最佳答案

为什么不只是:

while True:
    print "Which wire do you pull?"
    print
    print "1. The red one."
    print "2. The blue one."
    print
    raw_input('*>>*')
    if randint(0, 1):
        print "**BOMB DEFUSED**"
        return 'engineering2'
    else:
        print "**FAILED**"
        return 'death'

/!\raw_input 返回一个字符串,你将返回值与一个整数进行比较,它永远不会匹配:

$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 == "1"
False

关于python - 文本冒险中匹配用户选择的问题。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14675080/

相关文章:

python - 了解神经网络在文档示例 (MNIST) 中到底预测什么

python - python 中方程式的错误答案

python - 在 Django 中获取早于 10 天的数据库表数据

python - 使用 PyPDF2 合并两个 pdf 文件时出错

javascript - 如何在HTML和JS文件之间建立双向连接?

Python Google Analytics OAuth 服务帐户和 2LO; "sub"参数和域范围委托(delegate)

python - matplotlib:savefig 和 show 之间不一致

python - 重新引发异常有什么意义?

c++ - 在使用 C++ 的简单文本 RPG 游戏中,变量的值没有改变

java - 从房间中取出元素并将其添加到库存中