python程序错误elif else if [关闭]

2023-12-31

def Game():

    # Story Background
    print "You decide to take a walk outside one night when you come accross a corn field."
    print "You notice an omnious sound coming from the other side of the maze."
    Enter = raw_input("Do you enter? (yes or no)")

    if Enter == "Yes" or "yes":
        print "You walk into the maze and the corn is so thick together you cant push through"
        print "so you walk down the isle surrounded by corn and you come to an intersection."
        turn = raw_input("Which way do you go? (Left, Right, Forward, Leave)")

        if turn == "Left" or "left":
            print "After you turn left you come accross a dead end and you are forced to turn around."
            print "You return to the intersection."
            turn2 = raw_input("Which way do you go? (Left, Forward, Leave)")

            if turn2 == "Forward" or "forward":
                print "you walk on deeper into the maze when you come to a left turn"
                print "you turn left and come accross a crossroad."
                turn3 = raw_input("Which way do you go? (Left, Right, Leave)")

                if turn3 == "Right" or "right":
                    print "You come to a dead end and are forced to turn around"
                    turn4 = raw_input("Which way do you go? (Forward, Leave)")

                    if turn4 == "Forward" or "forward":
                        print "You walk to a hole in the ground stopping you from moving any further"
                        print "the hole seems to be filled with snakes so you cant go through it."
                        print "you are forced to leave the maze."

                    elif turn4 == "leave" or "Leave":
                        print "you leave the maze and return home."

                    else:
                         print "you walk into a wall and go into an irreversable coma"

                elif turn3 == "Left" or "left":
                    print "You walk to a hole in the ground stopping you from moving any further"
                    print "the hole seems to be filled with snakes so you cant go through it."
                    print "you are forced to leave the maze."
                    print "you leave the maze and return home."

                else:
                    print "you walk into a wall and go into an irreversable coma"

            elif turn2 == "Left" or "left":
                print "you turn Left into the maze when you come by a strange man laying on the ground."
                man == raw_input("What do you do? (Help, keep going)")

                if man == "Help" or "help":
                    print "you help the man up and he knocks you out cold"
                    print "you wake back up in your bed at home"

                elif man == "keep going" or "Keep going":
                    print "You leave the man behing after stealing his wallet."
                    print "YOU HAVE REACHED THE END OF THE MAZE"
                    print "You realize the noise was the sound of a old farmer milking a cow."
                    print "The farmer nags at you for coming on private property."

                else:
                    print "you walk into a wall and go into an irreversable coma"

            elif turn2 == "leave" or "Leave":
                print "you leave the maze and return home."

            else:
                print "you walk into a wall and go into an irreversable coma"

        elif turn == "Forward" or "forward":
            print "you move forward into the maze when you come by a strange man laying on the ground."
            man == raw_input("What do you do? (Help, keep going)")

            if man == "Help" or "help":
                    print "you help the man up and he knocks you out cold"
                    print "you wake back up in your bed at home"

            elif man == "keep going" or "Keep going":
                    print "You leave the man behing after stealing his wallet."
                    print "YOU HAVE REACHED THE END OF THE MAZE"
                    print "You realize the noise was the sound of a old farmer milking a cow."
                    print "The farmer nags at you for coming on private property."

            elif turn == "leave" or "Leave":
                    print "you leave the maze and return home."

            else:
                print "you walk into a wall and go into an irreversable coma"

        elif turn == "Right" or "right":
            print "After you turn right you come into a left turn only path."
            print "You turn left and you come to a crossroad."
            turn = raw_input("Which way do you go? (Left, Right, Leave)")

            if turn == "Right" or "right":
                print "You come to a dead end and are forced to turn around"
                turn = raw_input("Which way do you go? (Forward, Leave)")

                if turn == "Forward" or "forward":
                    print "You walk to a hole in the ground stopping you from moving any further"
                    print "the hole seems to be filled with snakes so you cant go through it."
                    print "you are forced to leave the maze."

                else:
                    print "you walk into a wall and go into an irreversable coma"

            elif turn == "Forward" or "forward":
                print "You walk to a hole in the ground stopping you from moving any further"
                print "the hole seems to be filled with snakes so you cant go through it."
                print "you are forced to leave the maze."

            else:
                print "you walk into a wall and go into an irreversable coma"

        elif turn == "Leave" or "leave":
            print "you leave the maze and return home."

        else:
            print "you walk into a wall and go into an irreversable coma"



    elif Enter == "No" or "no":
        print "You walk on into the depths of the night and are robbed by a couple street thugs."

    else:
        print "you walk into a wall and go into an irreversable coma"






def main():

    Game()

main()

当我使用这个程序时,无论我在 python shell 中输入什么,它都会一遍又一遍地说同样的事情。它不会将 raw_input 语句放入上下文中并将它们放入 if 语句中


if Enter == "Yes" or "yes":

这不是如何or作品。这被解释为if (Enter == "Yes") or "yes":。在 python 中,非空字符串始终为 true,因此所有if这样的陈述将是真实的。我会建议类似的东西

if Enter.lower() == "yes":

它负责处理所有大写/小写组合。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python程序错误elif else if [关闭] 的相关文章

  • PyList_SetItem 与 PyList_SETITEM

    据我所知 PyList SetItem 和 PyList SETITEM 之间的区别在于 PyList SetItem 会降低它覆盖的列表项的引用计数 而 PyList SETITEM 不会 我有什么理由不应该一直使用 PyList Set
  • Python Nose 导入错误

    我似乎无法理解鼻子测试框架 https nose readthedocs org en latest 识别文件结构中测试脚本下方的模块 我已经设置了演示该问题的最简单的示例 下面我会解释一下 这是包文件结构 init py foo py t
  • KFold 和 ShuffleSplit CV 有什么区别?

    看起来 KFold 每次迭代对象时都会生成相同的值 而 Shuffle Split 每次都会生成不同的索引 它是否正确 如果是这样 其中一个相对于另一个有什么用处 cv cross validation KFold 10 n folds 2
  • Python:记录垃圾收集器

    我有一个 python 应用程序 有一些性能问题 我想将垃圾收集器的事件 特别是何时调用 添加到我的日志中 是否可以 thanks http docs python org library gc html gc set debug http
  • Python,将迭代函数变成递归函数

    我创建了一个输出 4 3 2 1 0 1 2 3 4 的迭代函数 def bounce2 n s n for i in range n print n n n 1 if n lt 0 for i in range s 1 print n n
  • 在Python中创建一个新表

    我正在尝试从数控机床中提取数据 事件每毫秒发生一次 我需要过滤掉一些用管道 分隔的变量分隔符 PuTTy exe 程序生成的日志文件 我尝试阅读熊猫 但列不在同一位置 df pd read table data log sep 日志文件的一
  • 错误:无法访问文件“$libdir/plpython2”:没有这样的文件或目录

    我正在运行 postgresql 9 4 PostgreSQL 9 4 4 on x86 64 unknown linux gnu compiled by gcc GCC 4 1 2 20070626 Red Hat 4 1 2 14 64
  • str.translate 给出 TypeError - Translate 采用一个参数(给定 2 个参数),在 Python 2 中工作

    我有以下代码 import nltk os json csv string cPickle from scipy stats import scoreatpercentile lmtzr nltk stem wordnet WordNetL
  • Django - 电子邮件发送两次

    每当我使用如下所示的电子邮件设置从views py调用下面的方法时 电子邮件的两份副本都会发送给收件人 并且我收到如下所示的错误 def sendEmailBasic request msg EmailMessage Request Cal
  • RuntimeError: 预期所有张量都在同一设备上,但发​​现至少有两个设备,cpu 和 cuda:0!使用我的模型进行预测时

    我使用变压器训练了一个序列分类模型 BertForSequenceClassification 我收到错误 预计所有张量都在同一设备上 但发 现至少有两个设备 cpu 和 cuda 0 在方法wrapper index select中检查参
  • Python 视频框架

    我正在寻找一个 Python 框架 它将使我能够播放视频并在该视频上绘图 用于标记目的 我尝试过 Pyglet 但这似乎效果不是特别好 在现有视频上绘图时 会出现闪烁 即使使用双缓冲和所有这些好东西 而且似乎没有办法在每帧回调期间获取视频中
  • 如何检查列表是否为空?

    这个问题的答案是社区努力 help privileges edit community wiki 编辑现有答案以改进这篇文章 目前不接受新的答案或互动 例如 如果通过以下内容 a 我如何检查是否a是空的 if not a print Lis
  • 如何在 Python 中从 HTML 页面中提取 URL [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我必须用Python 编写一个网络爬
  • 求解不等式系统时“多项式错误:仅允许使用单变量多项式”

    我想找到以下两个常数的区间cons1 and cons2我写了下面的代码 from sympy import Poly from sympy import Abs from sympy solvers inequalities import
  • 为什么“return self”返回 None ? [复制]

    这个问题在这里已经有答案了 我正在尝试获取链的顶部节点getTopParent 当我打印出来时self name 它确实打印出了父实例的名称 然而 当我回来时self 它返回 None 为什么是这样 class A def init sel
  • 从 IMDbPy 结果中的片目中获取电影 ID

    我正在尝试创建一个数据集 允许我根据 Python IMDb API 中的演员 ID 和电影 ID 加入演员和电影 现在 我正在尝试从演员的电影作品中提取电影 ID 列表 但无法做到 例如 我知道 Rodney Dangerfield 在
  • Spark中的count和collect函数抛出IllegalArgumentException

    当我使用时抛出此异常时 我尝试在本地 Spark 上加载一个小数据集count 在 PySpark 中 take 似乎有效 我试图搜索这个问题 但没有找到原因 看来RDD的分区有问题 有任何想法吗 先感谢您 sc stop sc Spark
  • 为什么 bot.get_channel() 会产生 NoneType?

    我正在制作一个 Discord 机器人来处理公告命令 当使用该命令时 我希望机器人在特定通道中发送一条消息 并向用户发送一条消息以表明该命令已发送 但是 我无法将消息发送到频道 我尝试了这段代码 import discord import
  • issubclass() 对从不同路径导入的同一类返回 False

    目的是实现某种插件框架 其中插件是同一基类 即 A 的子类 即 B 基类使用标准导入加载 而子类使用 imp load module 从众所周知的包 即 pkg 的路径加载 pkg init py mod1 py class A mod2
  • Python 枚举子集迭代

    我想迭代以下枚举的子集 class Items enum Enum item1 0 item2 1 item3 2 item4 3 item5 4 item6 5 item7 6 item8 7 说我想 for item in Items

随机推荐

  • 在 SparkSQL 中使用 Avro 模式和 Parquet 格式进行读/写

    我正在尝试从 SparkSQL 写入和读取 Parquet 文件 出于模式演变的原因 我想在写入和读取中使用 Avro 模式 我的理解是 这可以在 Spark 之外 或在 Spark 中手动 使用例如AvroParquetWriter 和
  • 旋转端口登陆Android4.X后如何避免智能手机中的剪切/复制/粘贴?

    我正在努力避免在智能手机中剪切 复制 粘贴 对于平板电脑来说没问题 它在端口模式下很好 但在陆地模式下 EditText 显示一个 下一步 按钮 选择文本后 下一个按钮将转换为具有复制 剪切和粘贴选项的编辑按钮 那么 当编辑按钮出现时 有什
  • Java 中条件运算符内部的转换

    这会在 Eclipse IDE 中出现错误 错误符号出现在行号附近 String allText null 之后我做了一些事情 比如初始化数组等等 但要根据一些条件 所以我想使用如下所示的条件运算符 List
  • 是否可以仅在加载所有模块后才显示 shell?

    我目前正在开发一个应用程序 该应用程序使用 PRISM 4 将其功能划分为不同的模块 我注意到我的应用程序的 Shell 在其区域中保存了模块的视图 在加载模块之前加载并显示 这意味着首先显示 Shell 然后在相当长的时间 大约半秒 之后
  • 不带括号和带括号调用函数有什么区别

    在 onPressed 或 Ontap 上调用不带括号的函数和带括号的函数有什么区别 我只知道在 onPressed 上不能用括号调用 void 函数 floatingActionButton FloatingActionButton on
  • mutate 是否通过引用更改 tbl?

    我真正喜欢的是什么data table is the 通过引用更改表的习惯用法 无需昂贵的副本 据我了解 这是使data table与其他方法相比 速度超快 现在 我开始玩dplyr包似乎具有同样的性能 但由于结果仍然必须使用 lt 操作员
  • java 中的同步 - 正确使用

    我正在构建一个在多进程 线程 中使用的简单程序 我的问题更容易理解 什么时候我必须使用保留字同步 我是否需要在影响骨骼变量的任何方法中使用这个词 我知道我可以将它放在任何非静态的方法上 但我想了解更多 谢谢你 这是代码 public cla
  • 导轨和主干一起工作

    我刚刚开始研究 MVC 结构 首先我看看如何backbone js工作了 现在我刚刚完成僵尸的轨道 http railsforzombies org 由代码学校提供 我知道我还没有深入研究这些内容 但我首先有一个问题 您可以一起使用这些库吗
  • 错误:操作数 1 处向量寄存器的使用无效

    我正在 64 位 Aarch64 设备上的 ARM 下学习 GCC 内联汇编器 我看到一条我不太明白的错误消息 来自 GCC 内联汇编器的错误消息 gcc DNDEBUG g3 O1 march armv8 a crc crypto tes
  • codeigniter 允许 uri 中使用特殊字符(例如:ä、é、î、ø、ù)

    如何在 codeigniter 的 uri 中允许特殊字符 例如 您不能直接在 URL 中使用特殊字符 RFC 1738 包含以下段落 URL 只用图形来写 US ASCII 的可打印字符 编码字符集 US ASCII 字符集中的字符列表可
  • Rails 4 devise_invitable 邀请令牌无效

    我一直在关注Ryan Boland 的优秀 Rails 多租户教程 https www youtube com watch v nXqwFEjxyhM 但遇到了 devise invitable 的问题 我在用 Rails 4 1 5 de
  • 如何 IKVM Apache POI

    我想在我的 NET 应用程序中使用 Apache POI 我知道有一个端口 NPOI 但它不完整并且没有 PowerPoint 相关功能 我尝试使用以下命令对其进行 IKVM ikvmc target library poi 3 8 jar
  • biblatex:自定义参考书目条目

    我目前正在努力处理我的 BibLaTeX 文件 我想把这两个信息变成粗体 我正在使用下面的模板 但找不到插入的正确位置textbf or a 马克比博尔德属性 甚至不知道在这个用例中这是否是正确的属性 每次尝试都失败和 或使我的整个项目崩溃
  • Django 多对多限制

    我是数据库和 Django 的新手 我对触发器了解甚少 我创建了一个关于学术专家系统的数据库 这里所有论文最多应有 4 个主题 如果选择的主题多于 则应发出 主题过多 的警告 一个主题可以由许多论文拥有 所以这是一种多对四的关系 但我不知道
  • 如何从 C# 代码调用 Google 地理编码服务

    我有一个 C 类库 从那里我必须调用谷歌服务并获取纬度和经度 我知道如何在页面上使用 AJAX 来完成此操作 但我想直接从我的 C 类文件调用 Google 地理编码服务 有什么方法可以做到这一点 或者我可以使用任何其他服务来实现此目的 你
  • 用 Haskell 编写 Zipwith

    我正在尝试写ZipwithHaskell 中的函数 如果我使用以下值运行它 它应该返回以下结果 Prelude gt zipWith 10 20 30 33 44 94 43 64 124 到目前为止我的代码是 Zipwith f Zipw
  • Google 电子表格“无法调用 null 的方法“getRange””

    如果 B 列从第六行开始的每一行都发生了变化 我想在 A 列中生成一个唯一的 ID 使用 1 到 X 之间的数字作为 ID 就足够了 但在移动 de row 后它不应该改变 但我不断收到错误 无法调用 null 的方法 getRange f
  • 使用所有插件引导新的 Eclipse 机器

    在新机器上引导 Eclipse 是一个非常耗时的过程 您最终会问自己是否真的需要每个插件 但这一切都很方便 并且有助于养成一致的习惯 Eclipse 引导问题包括 解释 记录需要发生的事情 粘贴正确的 URL 并下载的实际时间 版本兼容性和
  • Linux:信号处理程序执行可以被抢占吗?

    我遇到了以下信号处理程序代码 它存储 errno 变量 以便它不会影响主线程的 errno 处理 void myhandler int signo int esaved esaved errno write STDOUT FILENO Go
  • python程序错误elif else if [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions def G