Question: I want to make sure that when the user inputs, for example, a 6 into the choice prompting for one of five choices that the program will ask them to enter a valid value and then continue with their new choice. However, when I finally do enter a valid choice after entering an invalid one, the code just stops. How can I get it to take their new choice?
Also, when I enter 1 as the value in the Ashe part where you talk to him, it replies with the second option because of the “else” statement. Why won’t it take the 1?
#IMPORTS
#FUNCTIONS
#create a function to print the instructions to shrink the main area
def printInstructions():
print(" ")
print("INSTRUCTIONS:")
print("You are playing as Noel Levine. Your childhood friend Claire Elford has the witch's heart within her, though unknowingly. The heart can grant any one wish for a person, but to get it, that person would have to kill her.")
print(" ")
print("Trapped in a haunted mansion with 3 others and Claire for five days, you fear for her safety. Thankfully nobody knows she has the heart except you, but if you make the wrong choices, anyone could kill her. Your job is to prevent that from happening, even if Claire doesn't remember who you are. \n\n To make choices, enter only the number that corresponds to that choice.")
#function to make sure the user input is either 1 or 2 so that they can make a choice between two options
def validateChoice2(x):
while x != "1" and x != "2":
x = input("\nThat's not a valid choice! Please input the number of the choice you wish to make: ")
return x
#function to make sure the user input is either 1, 2, 3, 4, or 5 so that they can make a choice between five options
def validateChoice5(x):
while x != "1" and x != "2" and x != "3" and x != "4" and x != "5":
x = (input("\nThat's not a valid choice! Please input the number of the choice you wish to make: "))
return x
#MAIN
#lists for choices the player has made and for the endings
choicesList = []
endingsList = ["COMMON BAD END: MONSTER WINS.", "ASHE WINS.", "WILARDO WINS.", "YOU WIN!"]
#game start
print("-----WITCH'S HEART SIMULATOR-----")
printInstructions()
print(" ")
#so the program doesn't keep running ahead of the user
input("Type anything to continue. ")
print(" ")
#context for the game and character intros
print("DAY 1 - INTRO. \nGathered in the dining room, the five of you trapped in the mansion make your introductions. The man with the teal braid and green outfit introduces himself as Ashe Bradley, a witch researcher. The man named Wilardo Adler has dark blue hair with a red streak, appearing cold and mysterious. The man with short purple hair calls himself Sirius Gibson, supposedly the lord of the mansion. You already know each other, but everyone else doesn't know that yet. Claire Elford, the one who you're here to save, sports a light blue bob and an enthusiastic smile. And of course, you're Noel Levine, with blond hair and dark blue clothes.")
print(" ")
#first choice, validate using function and the append to the list of choices
choice = input("After the introduction, everyone decides to split ways. Who would you like to spend the day with?\n \nCHOICE: 1. ASHE, 2. WILARDO, 3. SIRIUS, 4. CLAIRE, 5. NOBODY. ")
validateChoice5(choice)
choicesList.append(choice)
#check what choice the user has made by seeing what number is at index 0 in the choices list
#if they chose ashe
if choicesList[0] == "1":
print("\n\"Huuuh? Hey Noel! What do you need?\" Ashe is curious to see you follow him.")
#another choice to be validated
choice = input("\nWhat would you like to say? \n \nCHOICE: 1. \"JUST WANTED TO TALK.\" or 2. \"DO YOU KNOW ABOUT THE WITCH'S HEART?\" ")
validateChoice2(choice)
#nested if statement for choice after a choice
if choice == "1":
print("\nYou earn a smile from Ashe. \"Oh, no problem then! Well, I guess I can tell you a little more about me. Like I said, I'm a witch researcher. I came here to find some information on the evil witch Dorothy... they say this might be her mansion! That's why I don't trust Sirius entirely, because how could it be his?\" \n \n\"Anyway, have you ever heard the legend of the witch's heart? Super cool, right? Turns out it's not just a fairytale... and it may be hiding in this very mansion! Ooh, it would help my research so much to find it...\" \n \nYou learned a little more about Ashe!")
else:
print("\nAshe looks a little surprised at the question, but he nods excitedly. \"Yeah, of course! It's only the coolest thing ever! Turns out it's not just a fairytale... and it may be hiding in this very mansion! Ooh, it would help my research so much to find it... but, maybe I never will.\" \n \nYou learned a little more about Ashe!")
#if they chose wilardo
if choicesList[0] == "2":
print("\nWilardo gives you a strange look, but he does not make you leave. He doesn't seem to be the type for conversation, so you sit quietly with him in his designated room for the entire day. Wow, how boring!")
#if they chose sirius
if choicesList[0] == "3":
print("\nSirius is not amused to see you. \"I'm busy. Go bother someone else,\" he snapped, heading into his room and shutting the door on you. Hm.. well, it appears you'll be spending the day alone. \n \nYou explored the mansion by yourself, encountering low-level demons along the way. Nothing you can't fight off. Unfortunately, there doesn't seem to be anything helpful around here.")
#if they chose claire
if choicesList[0] == "4":
print("\n\"Noel? Hi! You wanna explore together? I thought maybe we could look around to find something useful, and then cook dinner for everyone later!\"")
choice = input(("\nWhat would you like to say? \n \nCHOICE: 1. \"SURE!\" or 2. \"SORRY, I'M GOING TO BED.\" "))
validateChoice2(choice)
#choice within a choice
if choice == "1":
print("\n\"Cool! C'mon, I wanted to look at these demons...\" You and Claire explore together, taking note of the low-level demons you worked together to fend off. Inspecting the front door, you noticed there was some kind of magic circle or ward on it, but you couldn't be sure what it did. Maybe that was what trapped you here, who knows. \n \nAfter a long day of exploring the massive mansion, the two of you got to work on preparing dinner for the others. \"Salisbury steak?\" Claire suggested, so you nodded and helped her make it. With lots of laughter and mishaps, it was a fun day, and the food looked delicious. \n\nYou had fun with Claire!")
else:
print("\nYou left Claire to explore and make dinner by herself. Taken by surprise, a demon in the mansion attacked her and killed her.\n")
#game ends here
print(endingsList[0])
#if they chose nobody
if choicesList[0] == "5":
print("\nYou decide to spend the day alone in your room, falling asleep until dinner. Talk about a waste!")