-2

I've just started to make a text-based adventure game and started to make the intro but ran into a problem...

I want to be able to let the player choose their gender (which is pointless but hey why not). So I started to program it in but then encountered a problem.

Here's what I have. So far...

#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()

I'm also getting the error message:

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

1 Answers1

0

You had a ton of syntax errors in your code. I would recommend exploring a good IDE (integrated development environment) like PyCharm because these programs will yell at you if you have indented things incorrectly, made a typo, etc. They are invaluable.

I have edited your code to give you a start on better understanding how a program should be put together. Problems fixed include:

(1) Your multi-line strings need to be concatenated together somehow; I used the + operator

(2) Python is strict about indentation; many of your blocks were improperly indented. See https://docs.python.org/2.0/ref/indentation.html, and

(3) If you actually want to use a main() function you might as well do it the canonical way. This is typically a function that wraps everything else together and then is run under 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()
HFBrowning
  • 2,196
  • 3
  • 23
  • 42
  • Sweet thanks for the help. I've noticed the indentation error when messing around with it a little bit more. I haven't learned about the if __name__ == "__main__": thing yet but ill look it up. – Ender Kid Mar 13 '18 at 22:02
  • You're welcome. The last point isn't always strictly necessary but is certainly a helpful convention, and it's quite commonly seen in command line based games. https://stackoverflow.com/questions/419163/what-does-if-name-main-do – HFBrowning Mar 13 '18 at 22:04