Please help me finish my project. I am a novice and completely new to python and hopelessly lost. I hope somebody will be able to help me. Here is my problem, I am working on a project for class and I am stuck. My program is supposed to be simple, yet I find nothing remaining to be done a simple matter, my loops are infinite and my input validation is shot. My program ask the user to make some choices and should tally the score and print out a rating based on the accumulated score, it then should ask whether the user would like to play again or not. There are six main scenarios for the user to traverse through their choices and I would like for the program not to repeat any of the scenarios on a single play through. Here is my code, please help! all advice is appreciated.
import random
#main menu
def main ():
score = 0
choice = 0
#The set up
print """Like it or not, there is no such thing as safe harbor from zombies.
They spread their infection like a two dollar Singapore whore spreads Chlamydia through the Navy,
they can survive without their limbs, and they’re always hungry."""
print """Let's face the facts; the odds are stacked against you,
and your chance of survival is low, very low.
However, if you make the right decisions you just might survive the imminent zombie apocalypse."""
print 'How long will you survive the undead uprising?'
starting_point()
playAgain ()
def starting_point(): #Get starting point
choice = 0
print """Where are you?
1. I’m in space.
2. I’m in some lab.
3. I’m in a rural town.
4. I’m in a mansion.
5. I’m at the shopping mall."""
#Decision structure to determine starting point
choose = get_choice(choice)
if choose == '1':
start = space
space()
elif choose == '2':
start = lab
lab()
elif choose == '3':
start = town
town()
elif choose == '4':
start = mansion
mansion()
elif choose == '5':
start = mall
mall()
else:
isInvalid = 'True'
while isInvalid == 'True':
invalid_input()
starting_point()
return (start)
#Alternatives
def get_choice(choice):
choice = raw_input('Enter your choice now: ')
return (choice)
#Invalid input
def invalid_input():
print 'If you’re too dense to follow simple instructions, there is no hope for you.'
print #prints blank line
print 'Let’s face it, you’re zombie chow!'
print #prints a blank line
#This module shows conversation that is only available if space is chosen as the start
def space():
choice = 0
print """You’re in space!
What the hell are you doing in space?
1. Complaining about being in space.
2. Looking for that hot alien chick from Total Recall, the one with three boobs."""
choose = get_choice(choice)
if choose == '1':
print 'Well stop bitching, you’re the one who wanted to start in space.'
space_2()
elif choose == '2':
print 'You know you’re an idiot, right?'
space_2()
else:
isInvalid = 'True'
while isInvalid == 'True':
invalid_input()
space()
#space_2 module, main space module
def space_2():
choice = 0
print """Like it or not you’re in space. Why?
1. I’m searching for my lost girlfriend.
2. I’m answering a distress beacon.
3. I don’t know. I just thawed."""
choose = get_choice(choice)
if choose == '1':
print """Your girlfriend is a zombie!
How attached are you to her?
1. She’s the love of my life!
2. Meh…"""
choose = get_choice(choice)
if choose == '1':
print 'Oh noes! It’s a zombie honey moon.'
print 'Damn that’s disgusting!'
game_over()
elif choose == '2':
print """Honey I think we should start seeing other people…
Grab the breakup shotgun, things are gonna get messy.
But hey, at least it ended with a bang right?
Welcome back to earth."""
if start == mall:
crash()
else:
escape2_mall()
else:
invalid_input()
elif choose == '2':
print """It’s a trap obviously.
Space zombies!
What do you do?
1. Set collision course for the sun and escape via pod.
2. Dismember undead crew, and escape via pod.
3. Do space weapons take batteries?"""
choose = get_choice(choice)
if choose == '1':
crash()
elif choose == '2':
print 'You battle your way through the undead horde.'
print 'You barely manage to escape with your life.'
escape2_mall()
elif choose == '3':
game_over()
else:
invalid_input()
elif choose == '3':
print 'Oh no you’re naked and that is a zombie!'
game_over()
else:
invalid_input()
#Lab module,
def lab():
choice = 0
print """You’re in a lab. You’re not sure how you got here.
Take a look around, what do you see?
1. Fleshy, asymmetrical monsters floating in massive incubation tubes.
2. An unskippable cutscene starring the recurring villain."""
choose = get_choice(choice)
if choose == '1':
escape = raw_input('Have any of them escaped?(y or n): ')
while escape == 'n':
print 'Everything is probably fine.'
print 'What was that noise?'
print """What are you going to do?
1. Run like hell.
2. Grab my trusty rocket launcher."""
choose = get_choice(choice)
if choose == '1':
print 'You manage to find a helicopter and escape.'
town()
elif choose == '2':
print """Time to blow stuff up!
Oohh! Is that a space ship?'
You manage to escape on the space ship,
after you set off a chain reaction of explosionsof course."""
space_2()
else:
invalid_input()
elif choose == '2':
print """Cut to preachy monologue about the nature of man.
1. Activate self destruct while villain is distracted.
2. This is boring, gonna go make a sandwich."""
choose = get_choice(choice)
if choose == '1':
print """While the villain is busy talking,
you press the self destruct button and sneak off.
Oh what luck, a helicopter!"""
town()
elif choose == '2':
game_over()
else:
invalid_input()
else:
invalid_input()
#Rural town module
def town():
choice = 0
print """You’re in a small rural town and decide to join forces
with one of the local zombie resistance groups.
Who are you with?
1. The red neck militia.
2. The town’s lovable odd-balls."""
choose = get_choice(choice)
if choose == '1':
print """What are they armed with?
1. Guns… but no armor.
2. Who cares, they have beer!"""
choose = get_choice(choice)
if choose == '1':
print """You listen to them whine about inevitable flesh wounds.
What are you going to do about it?
1. Shoot em in the face.
2. Wait it out."""
choose = get_choice(choice)
if choose == '1':
print 'Now that you’ve disposed of the dead weight,'
shelter()
elif choose == '2':
print 'Sgt Bubba gives you a love bite.'
print 'You start feeling ill, and chronicle symptoms in your diary.'
game_over()
else:
invalid_input()
elif choose == '2':
print 'You’re way too drunk to fight off the zombies.'
print 'Fortunately you’re also too drunk to feel it.'
game_over()
else:
invalid_input()
elif choose == '2':
shelter()
else:
invalid_input()
#Shelter module call’s two other modules
def shelter():
choice = 0
print """You need to seek shelter.
Where do you go?
1. Parent’s house.
2. Motel."""
choose = get_choice(choice)
if choose == '1':
parents()
elif choose == '2':
motel()
else:
invalid_input()
#Parents house
def parents():
print """Is that a zombie on the lawn?
You run in the house to find your parents.
Oh no! Your parents are zombies!"""
game_over()
#Motel
def motel():
print """To while away the time you talk
to the manager with glass eye about end of days.
As the manager falls asleep you unceremoniously steal his glass eye.
You conveniently stumble upon a large iron gate with eye-shaped hole."""
mansion()
#mansion module, the puzzles were cut due to lack of know how
def mansion():
choice = 0
solitude = raw_input('Are you alone?(y or n): ')
while solitude == 'n':
print 'Time to split up!'
print """Damn nobody told me there were going to be puzzles.
You spend many hours solving the same puzzles over and over.
After all that effort the bookcase finally moves revealing…
Zombies!
What do you do?
1. Run.
2. Fight."""
choose = get_choice(choice)
if choose == '1':
print 'You can’t seem to run fast enough.'
game_over()
elif choose == '2':
print '1. Crap, I exchanged my ammo for an ink ribbon.'
print '2. Battle through zombie horde.'
choose = get_choice(choice)
if choose == '1':
game_over()
elif choose == '2':
print """What is this, some kind of elevator?
What is this, some kind of tunnel?
What is this, some kind of ladder?
Getting kind of redundant isn’t it?
What is this, some kind of hand trolley?
Are you serious?"""
lab()
else:
invalid_input()
else:
invalid_input()
#shopping mall modules
def escape2_mall():
parking_lot()
mall()
def parking_lot():
print """Your escape pod lands in the mall parking lot,
and you make a mad dash for the doors with yet another
horde of undead right behind you."""
def mall():
choice = 0
print """You manage to make it inside the mall just before the
other survivor’s barricade the doors shut.
Who do you team up with?
1. The endearing old couple.
2. The promiscuous co-ed.
3. The janitor with the walkie-talkie.
4. The disgraced ex-cop searching for his daughter."""
choose = get_choice(choice)
if choose == '1':
print 'That was stupid.'
game_over()
elif choose == '2':
print """You barricade your selves in the food court,
and defile the Orange Julius stand.
Zombies break through your barrier and catch you with your pants down.
It was totally worth it."""
game_over()
elif choose == '3':
print """Listen to his life story.'
Take maintenance tunnels to roof where rescue awaits.'
Last stand against zombie horde.'
1. Help janitor.
2. Leave janitor."""
choose = get_choice(choice)
if choose == '1':
game_over()
elif choose == '2':
print 'You shed a single tear for the janitor as you are rescued.'
town()
else:
invalid_input()
elif choose == '4':
print """Provide comic relief while cop does all the killing.
Cop helps you believe in yourself as you make it to roof.
Last stand against zombie horde.
1. Cop abandons you.
2. Cop abandons you, aim for the choppers gas tank in retaliation."""
choose = get_choice(choice)
if choose == '1' or choice == '2':
game_over()
else:
invalid_input()
else:
invalid_input()
#Crash module, scenario ends with barn module
def crash():
choice = 0
print """The last thing you remember is a crash…
Are you in a barn?
1. Yes.
2. No, it’s a shed."""
choose = get_choice(choice)
if choose == '1':
barn()
elif choose == '2':
print 'Close enough, smart ass.'
barn()
else:
invalid_input()
#Barn module, closes the crash scenario.
def barn():
choice = 0
print """Is it 1943?'
1. Yes.
2. No, it’s 1955."""
print 'Enter choice now'
choose = get_choice(choice)
if choose == '1':
print 'Nazi zombies!'
game_over()
elif choose == '2':
print 'You are Marty McFly'
else:
invalid_input()
#survival rating
def survival_rating(score):
#Declare local variables
one = """Save a bullet for yourself.
No need to put your friends and family through the anguish of having to blow your head off."""
two = """You’re chances of survival are low,
better hope your friends don’t consider you a liability during the uprising."""
three = """Your chances of survival are average,
you might even be able to make it to the nearest militarized “safe zone”, maybe."""
four = """Above average chances of survival,
it won’t be easy, but hey you always did want to shoot somebody in the face."""
five = """It is going to take more than a few hundred zombies to ruin your day.
Congratulations, you are officially a badass."""
six = """It would take a nuclear blast to remove you from the face of the earth.
Zombies don’t stand a chance."""
if score == 1:
print one
elif score == 2:
print two
elif score == 3:
print three
elif score == 4:
print four
elif score == 5:
print five
elif score == 6:
print six
else:
print """You are more than likely to be patient zero.
I hope you’re happy with yourself,
because the apocalypse is probably your fault."""
print 'Way to go dick.'
#The game over message
def game_over():
number = random.randint(1, 5)
if number == 1:
print 'You are dead.'
elif number == 2:
print 'Being eaten alive is an unpleasant way to die.'
elif number == 3:
print 'Game over.'
elif number == 4:
print 'The zombies pick your bones clean.'
else:
print 'The undead walk the Earth, and you are now among them.'
#Play again module
def playAgain ():
playAgain = raw_input('Would you like to try again?(y or n)')
if playAgain == 'y':
starting_point()
elif playAgain == 'n':
print """Thank you for playing.
The brains were delicious!"""
else:
invalid_input()
main()
Once again, any help is greatly appreciated. Please keep in mind that I am a noob and this program is still in the process of being written and is somewhat incomplete.