0

I am making a text adventure game and I am trying to allow the user to quit the game using q. I don't know what to input, here's my code.

print ("Welcome to Camel!")
print ("You have stolen a camel to make your way across the great Mobi deset.")
print ("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")

print ("Welcome to Camel!")
print ("You have stolen a camel to make your way across the great Mobi deset.")
print ("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")

done = False
while done == False:
    print("Print the letter only.")
    print("A. Drink from your canteen.")
    print("B. Ahead moderate speed.")
    print("C. Ahead full speed.")
    print("D. Stop for the night.")
    print("E. Status check.")
    print("Q. Quit.")

    first_question = input("What do you want to do? ")

    if first_question.lower() == "q":
        done = True

    if done == True:
        quit

The lines are all indented properly in the code (the website makes it weird when copy pasting). Any help is appreciated.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    I edited your code into a code block. In the future, you can highlight the section of code and click the button with the curly brackets `{}` to indent it for you – James Nov 15 '16 at 00:26
  • See https://stackoverflow.com/questions/543309/programatically-stop-execution-of-python-script – AnilRedshift Nov 15 '16 at 00:38
  • what is `quit` ? maybe you mean `break` or `quit()` - with `()`. But remove `if done==True:quit` and it should work as you expect. – furas Nov 15 '16 at 00:50
  • You could use either `if done: break` _or_ `if done: sys.exit()`. – martineau Nov 15 '16 at 01:05

2 Answers2

1

Your program is nearly fine as is, and in fact it runs just fine in python3. The problem is that in python2, input will actually evaluate your input. In order to support python2, use raw_input.

Hamms
  • 5,016
  • 21
  • 28
-1
print ("Welcome to Camel!")
print ("You have stolen a camel to make your way across the great Mobi deset.")

print ("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")

done = False

while done == False:

    print("Print the letter only.")

    print("A. Drink from your canteen.")

    print("B. Ahead moderate speed.")

    print("C. Ahead full speed.")

    print("D. Stop for the night.")

    print("E. Status check.")

    print("Q. Quit.")

    first_question = input("What do you want to do? ")

    if first_question.lower() == "q":

        done = True

        if done == True:

            break

Now, when you input 'Q' or 'q' program will quit. It's about tabulation. Is that what you asked?