Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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游戏中创建性别?_Python_Python 3.x - Fatal编程技术网

如何在基于文本的python游戏中创建性别?

如何在基于文本的python游戏中创建性别?,python,python-3.x,Python,Python 3.x,我刚开始做一个基于文本的冒险游戏,开始做介绍,但遇到了一个问题 我希望能够让球员选择他们的性别,这是毫无意义的,但嘿,为什么不。所以我开始编程,但后来遇到了一个问题 这是我的。到目前为止 #Date started: 3/13/2018 #Description: text based adventure game import random import time def main(): def displayIntro(): print('It is the end of a

我刚开始做一个基于文本的冒险游戏,开始做介绍,但遇到了一个问题

我希望能够让球员选择他们的性别,这是毫无意义的,但嘿,为什么不。所以我开始编程,但后来遇到了一个问题

这是我的。到目前为止

#Date started: 3/13/2018
#Description: text based adventure game

import random
import time

def main():

def displayIntro():
    print('It is the end of a 100 year war between good and evil that had 
           killed more than 80% of the total human population.')
    time.sleep(4)
    print('The man who will soon be your father was a brave adventurer who 
           fought for the good and was made famous for his heroism.')
    time.sleep(4)
    print('One day that brave adventurer meet a beautiful woman who he later 
           wed and had you.')
    time.sleep(4)

gen = ""
while gen != "1" and gen != "2": # input validation
    gen = input('Your mother had a [Boy(1) or Girl (2)]: ')
return gen


playname = input('They named you: ')


displayIntro()
main()
我还收到了错误消息:

File "<ipython-input-1-940c72b6cc26>", line 10
  def displayIntro():
    ^
IndentationError: expected an indented block

代码中有大量语法错误。我建议探索一个好的IDE集成开发环境,比如PyCharm,因为如果您缩进错误、输入错误等,这些程序会对您大喊大叫。它们是非常宝贵的

我编辑了你的代码,让你开始更好地理解程序应该如何组合在一起。修复的问题包括:

1您的多行字符串需要以某种方式连接在一起;我使用了+运算符

Python对缩进要求严格;您的许多块缩进不正确。看到了吗

3如果你真的想使用一个主函数,你最好用规范的方法。这通常是一个将所有其他内容打包在一起的函数,然后在if\uuuuu name\uuuuu==\uuuuuuuuu main\uuuu:下运行


看起来返回语句周围的缩进已关闭。my bad忘记添加它显示此错误文件,第10行def displayIntro:^IndentationError:应为缩进block@EnderKid用相关信息编辑问题。我一直在想办法编辑,但找不到。更不用说找到了。谢谢你的帮助。我注意到了缩进错误,当我把它弄得乱七八糟的时候。我还没有学会if name==main:这个东西,但我会查一下。不客气。最后一点并不总是严格必要的,但肯定是一个有用的惯例,在基于命令行的游戏中非常常见。
import random 
import time 


def display_intro():
    print('It is the end of a 100 year war between good and evil that had \n' +
           'killed more than 80% of the total human population. \n')
    time.sleep(4)
    print('The man who will soon be your father was a brave adventurer who \n' +
           'fought for the good and was made famous for his heroism. \n')
    time.sleep(4)
    print('One day that brave adventurer meet a beautiful woman who he later \n' +
           'wed and had you. \n')
    time.sleep(4)


def get_gender(gen=None):
    while gen != "1" and gen != "2":  # input validation
        gen = input('\nYour mother had a [Boy(1) or Girl (2)]: ')
    return gen


def main():
    display_intro()
    gender_num = get_gender()

    print("This is a test. You entered {}".format(gender_num))


if __name__ == "__main__":
    main()