'I cannot seem to find a way to restart my python 3 game after the else function hits
To clarify I dont really want the player to have to restart from the very beginning. I want them to trigger the else function (when typing in an answer to an input that doesnt exist/work) and then go back to that input. Is there a way to make this happen. My else function currently does a deadpool cameo and then it just ends. I could add in a basic restart from the beginning (i have a def main() at the start of the entire code, and i use that for "game over" scenarios) but i want to give the option to restart from when they entered an invalid response as well.
def main():
print('You are a young adventurer seeking your fortune amoung the ruins of Old Faeridan. You left home with only your fathers old armor, your mothers used bow, and a sword passed down in your family for generations.')
choice1 = input('As you reach the entryway to the ruins, you notice a small pile of coins in the corner, near an open door. You take a moment to consider if you should GRAB the pile of coins, or keep GOING. :')
if choice1.lower() == 'grab':
action1 = input('As you reach forward to grab the shiny gold pieces, a giant spider lunges from the darkened doorway near the pile and grabs your arm! Do you swing your SWORD, or PUNCH it in the eyes? :')
if action1.lower() == 'punch':
choice1action1 = input('You pull back a fist and slam it into one of the disgusting creatures massive eyes. Green slime explodes from its face as the eye pops and it screams in pain before letting go and leaving you wounded on the ground. You pull yourself together and grab the coins, a bit richer and much wiser than when you started your journey. As you rise to your feet and tear a piece of your clothing to wrap around the wound you wisely decide to back away from the dark doorway, in case the beast had friends. There is a brightly lit way FORWARD, or a small windy staircase that ASCENDs upwards before you. :')
if choice1action1.lower() == 'ascend':
print('you die')
elif choice1action1.lower() == 'forward':
choice1action2 = input('You walk forward carefully, keeping your eyes peeled for any sign of more dangers. Finding nothing you come into a lare chamber, full of large windows that have remains of stained glass around the edges. Obviously this was once a grand hall of some kind. In the center of the hall is a small pedastal, upon which rests a golden egg the size of your fist. The egg is topped with a glittering diamond and the foot of the pedastal is surrounded by small golden statues of some type of colerful bird, facing inwards as if to worship the egg. It is an amazing sight and the treasure that the egg or the statues alone could give to your family is immense, exactly what any adventurer could hope to find. Do you reach down to grab a STATUE, or lean in to pick up the EGG? :')
if choice1action2.lower() == 'statue':
print('You happily pick up a few golden statues and quickly leave the ruins, content in the knowledge that you came out of your adventure much richer, a bit wiser, and with only a few scars on your arm. You return home to admiration and a large celebration held in your honor! Enjoy your well earned retirement!')
elif choice1action2.lower() == 'egg':
print('As you touch the egg, your fingers start to glow, and a golden hue covers your skin. You desperately wipe at your hand but the golden color doesnt come off and you realize with horror that you are turning into gold. As you take this fact in, your body starts to shrink and change as your feet become talons and your arms wings. You try to move, to run, but your new talons are stuck fast to the floor and soon you lose all sense of reason and self as a cloud overcomes your mind. You would feel terrified, if you could anymore, but you can only stand blankly as you are tranformed into just another golden bird statue, forever worshipping the egg.')
retry = input('GAME OVER, would you like to try again? YES/NO :')
if retry.lower() == 'yes':
main()
if retry.lower() == 'no':
print('You are forevermore a lost golden statue, cursed to worship the golden egg for all eternity, and apparently your ok with that!')
elif action1.lower() == 'sword':
print('Your sword clangs off the spiders very thick carapace and its fangs dig into your neck as it pulls you away to be devoured. Sadly your adventure ends here, as a meal for a gigantic pest.')
retry = input('GAME OVER, would you like to try again? YES/NO :')
if retry.lower() == 'yes':
main()
if retry.lower() == 'no': print('A flying man in blue underwear and a red cape shows up and gives you a salute before flyng off into the sky.')
elif choice1.lower() == 'going':
choice2 = input('As you pass the coins, you see the glittering of many eyes in the darkness of the doorway nearby and are suddenly very glad you left the wealth behind. You continue farther in and come across a table that is heavily laden with fresh food and wine. After the journey here you are famished, do you EAT, or PASS up this bounty? :')
else: print('A voice rings out, as a red costumed man with two swords and a domino mask appears before you and wags his finger "bad player, you have to make a choice! Now, im off the annoy the man who looks like a bat!" As he vanishes you swear you can hear him debating the joys of unicorns over pegasi.')
main()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|