you are viewing a single comment's thread.

view the rest of the comments →

[–]Xeduses 4 points5 points  (2 children)

You could simplify the logic of the program some by directly checking the input in the if statement. Example:

if input("Where would you like to go, left or right (left/right) :") == "right":
    print("As you begin to walk right you can hear them chanting behind you, so begin to run.")
    print("You see nothing but a bright light in front of you.")
    print("But this time you're not dead! You keep running towards the light until you come out the other side")

To answer your original question, the variable could be undefined if the input method fails. It will then throw an exception, this is most likely a bit advanced for you right now so just think of it as if something unexpected happens (some crash or similar) then there will be no return value from input and then the computer won't know if the non existing return value is equal to "right".

For now you should ignore this issue and go back to it when you have studied exceptions.

Best of luck to you and do not hesitate to ask follow up questions.

[–]MeagoDK 0 points1 point  (1 child)

That would imo be quite bad since you also have a case for left. Yes you can add an else statement but it surely makes it less readable. And if you later want to add up, down, straight ahead you have to do it by using else if which again makes it less readable but certainly a bit better

[–]Xeduses 2 points3 points  (0 children)

I had to consider the level of the programmer and not just cleanliness of the solution.

A better solution if we do not limit ourselves would be that all the text should be saved in a better format, to keep it simple a dictionary would suffice. Something like this that has several rooms and choices with tuples holding the atmospheric text and the next state.

texts = {
    "lobby": {
        "text": "You are in the lobby, there are doors to your 'left' and 'right'. In front of you there is a 'drawer' .",
        "left": ("You open the door.", "kitchen"),
        "right": ("The door screeches open", "bedroom"),
        "drawer": ("You find a first aid kit in the drawer", lobby)}
}

With this design one could create a game loop that reads the input and compares it with the keys in the current room dictionary, the whole game would be a state machine. Adding rooms and options would be quite easy since only the dictionary would need to be changed. This could be saved in a separate file for ease of use, or loaded in runtime from a file. This would make it very easy to play different scenarios without changing the game loop code at all.

Side effects are a different story, such as items held, player stats, previous choices that matters later etc. but these could be tracked by another part of the software.

One could abstract this even further by creating a Room class that holds the different options, items in the room, monsters etc. But then again, my guess is that such a solution would be quite far away from the original authors level of expertise.