Help
cancel
Showing results for
Did you mean:
Copilot Lvl 2
Message 1 of 2

## need help with python and pygame

Solved! Go to Solution.

Hi I'm making a text based game in pygame with python 2.7

Here is the problem

`answer = input("Sa arkad ules pimedas ruumis, sa ei tea kuidas sa sinna sattusid. Mida sa teed? KOBA RINGI/OOTA")if answer == "koba ringi":    answer = input("Sa kobad ringi ja leiad eseme mis tundub olevat valgumihkel. Kas sa tahad selle polema panna? JAH/EI")    if answer == "jah":        answer = input("See ei lahe polema. Peatselt sa kuuled samme, sa eeldad et sa oled kinnises ruumis. Mida sa teed? KARJU JUUST/OOTA")        if answer == "karju juust":            print "Sa saad millegiga pihta ja arkad ules oma toas voodis. See oli lihtsalt uni. SA VOITSID!"        elif answer == "oota":            print "Keegi jooksis ruumi ja virutas sulle vastu pead. SA KAOTASID!"    elif answer == "ei":        print "Keegi jooksis ruumi ja virutas sulle vastu pead. SA KAOTASID!"`

I want to move move between

`if answer == "karju juust":`

and

`if answer == "koba ringi":`

without ending the game

what is the best solution for that?

Sorry for my english and don't mind the text (it is in my own language).

Highlighted
Solution
Commander Lvl 2
Message 2 of 2

## Re: need help with python and pygame

Your sentence "I want to move between answer 'a' and answer 'b'" is a little unclear, so I'm a little uncertain about what you're trying to do.

If you are trying to re-use questions, or have additional sequences of questions, you might try using python functions to post questions and check answers. Since each of your questions are two-answer questions, you can return a boolean result from the functions.

```if (question1()):
if (question2()):
if (question3()):
goodend()
else:
else:
else:
if (question3()):
goodend()
else:

So above, the question1() function asks your first question, returns true if the answer is "koba ringi". question2() asks the second question, returns true if the answer is "jah". question3() asks the third question, returns true if the answer is "karju juust". But I've extended your logic so that if the answer to question1() is "oota", then question3() is called: the player wins if the answer is "karju juust".

Here is what the question1 function might look like:

```def question1():
answer = input("Sa arkad ules pimedas ruumis, sa ei tea kuidas sa sinna sattusid. Mida sa teed? KOBA RINGI/OOTA")

Asks the first question, and returns true if the answer is "koba ringi".

I hope the functions "goodend" and "badend" are obvious: merely print the "you lived" / "you died" results.

This way, you can string together your questions in a different order, or re-use questions.

I hope this helps ...

So to handle different possible answers without exiting, you'll need a loop. When the loop exits, the game is over.

You'll need to clarify what you want to do a little more. If you restated your sentence "I want to move between answer 'a' and answer 'b'" to be a little clearer, we could help you more easily, and the answer may even occur to you on your own!

New solutions

Top Kudoed Posts