Я делаю текстовую приключенческую игру на Python и пытаюсь добавить третий вариант, но он не работает

Я пытаюсь сделать простую текстовую приключенческую игру с тремя вариантами выбора. Но я не могу понять, почему это не работает.

Это код, над которым я работал:

#Text based medieval adventure game

#Imported libraries are required
import random
import time

def displayWelcome():
    print ("\nText adventure game\n")
    print ("Welcome to the medieval adventure game!")
    print ("You will have many choices through out this game")
    print ("Be sure to pick the right one")
    print ("          Good Luck!          ")

    answer = askYesNo("Would you like help with this program? (Y/N): ")

    if answer == "Y":
        helpForUser()
        time.sleep(3)

def askYesNo (question):
# This function will ask you a yes or no question and will keep asking until one is chosen.
# The following function is used to erase the variable response of any values
    response = None

    while response not in ("Y", "N"):

        response = input (question).upper()

    return response

def helpForUser():
#This function will show the user some helpful advice if they desire it
    print ("\n+++++++++++++++++++++++++++++++++++++++ Help +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print ("This game is a adventure text based game set in the medieval times")
    print ("You will be asked multiple questions with a yes or no response")
    print ("you must answer the questions with the answers supplied to you suches as yes or no")
    print ("If you don't answer the q uestion with the given answers it will be repeated untill a valid response occurs")
    print ("The program can end when you choose")
    print ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
def displayIntro():
    #Displays intro to game
    print ("\n It's been a rough day in the wild and you despratly need shelter")
    print ("There is currently a war going on and nowhere is safe")
    print ("But you intend to find somwhere with food and a bed but it wont be easy...")
    print ()



def choosePath(lower,middle,upper):
#This functions allows you to choose between multiple options
    path = 0
    while path < lower or path > upper:
        number = input("What path will you take(" + str(lower) + " - " + str(upper) + ")?: ")

    if number.isdigit():
        path = int (number)
    else:
        path = 0

    return path

def followPath(chosenPath):

    print ("you head down a long road\n")
    time.sleep(3)
    print ("You come across an abandoned campsite and decide to stay there for the night")
    time.sleep(3)
    print("You wake up to a sudden sound of voices and begin to realise that this campsite wasn't abandoned...")
    time.sleep(3)
    print("You start to freak out")
    time.sleep(3)

    if chosenPath == 1:
           print("You grab your sword out and decide to go out the tent")
           print ("Four well trained knights surround you")
           print ("They strike without any hesitation, you counter two knights trying to hit you from the front as two from behind stab you in the back")
           print ("The knights decide to burn your body and leave nothing left of you.\n")
    elif chosenPath == 2:
           print("You dart out of the tent and head for the exit")
           print("All the guards try and get you whilst shooting arrows")
           print("Several arrows hit you leaving you injured unable to run")
           print ("Suddenly a man with a giant axe appears before you and slices you head off in a clean swoop\n")
    else chosenPath == 3:
           print("You keep calm and decide to sneak past all the guards")
           print ("You're close to the exit when suddenly a guard notices you")
           print("He's about to call for back up when you dash right into his chest with your sword, leaving it in him and running out the campsite")
           print("You make it to a safe forest and decide to rest\n")




displayWelcome()
playAgain = "Y"
while playAgain == "Y":

    displayIntro()
    choice = choosePath()
    followPath(choice)
    playAgain = askYesNo ("Would you like to play again?")
print ("\nBye")

1 ответ

Ошибка номер один: строка 63, иначе должно быть elif или избавиться от условия. SelectedPath == 3: Текущее состояние

    else chosenPath == 3:

Как это должно выглядеть

    elif chosenPath == 3:

или же

    else:

Другая ошибка заключается в том, что при инициализации выбора ничего не происходит, потому что вы забыли ввести "нижнее, среднее, верхнее" значение.

Другие вопросы по тегам