Python Programmers

Infin1ty1

In Runtime
Messages
349
*EDIT*
It appears that when I quoted the text it got rid of all of my indents, please let me know if it is too difficult to read this way and I will figure out something.


Need some help with my program here. It runs without a problem, but I can't get the accumulator to work right. I've tried to set the accumulator values outside of the main module and within the individual modules.

When setting it outside of the main module, I get an error when I get the point of actually using the accumulators stating that the global name had not been declared yet.

When setting the accumulator values inside of the modules that they are actually used in, it of course resets the value every time you run that module.

Anyways, heres what I have. Like I said, it will run all the way through without issue, just can't get the accumulator to work correctly.

This is not a game, nor is it supposed to make sense 100%, so don't try to think too deeply into it when looking over it.

def main():

menu ()

def menu ():
choice = 0


while choice !=4:
print "Menu Selections"
print "1-Fire Weapon"
print "2-Move Forward"
print "3-Move Backward"
print "4-Exit"
choice = input ("Please input your choice: ")

if choice == 1:
fireWeapon ()
elif choice == 2:
moveForward()
elif choice == 3:
moveBackward()
elif choice == 4:
print "Thank you for using the Battlebot!"
else:
while choice > 4 or choice <1:
print "Your choice is invalid, you will now be returned to the main menu"
menu()


def fireWeapon():
ammunition=5

fireDistance= input ("How far away, in feet, is the target?:")
if fireDistance <= 0:
print "This is an invalid choice, you will now return to the main menu"
menu()
elif fireDistance <= 20:
print "You have destroyed the target!"
elif fireDistance <= 40:
print "The target is partially disabled!"
elif fireDistance > 40:
print "You have missed the target."
while fireDistance > 0:
ammunition = ammunition -1
fireDistance = 0

menu ()

def moveForward ():
fuel=200
feetForward = input ("How many feet forward would you like to move?:")
obstacle = input ("How many feet in front of you is the obstacle?:")

if feetForward > fuel:
print "This is an invalid entry, you will now be returned to the main menu."
menu()

if feetForward > obstacle:
feetForward = feetForward - obstacle
print "Your path is blocked, you will only be able to move ",feetForward,"feet forward."

else:
"you will now move ",feetForward,"feet forward."

while fuel > 0:
fuel = fuel - feetForward
print "You have ",fuel,"fuel remaining."
feetForward = 0
obstacle = 0
menu ()
while fuel < 0:
print "You do not have enough fuel to move, you will now be returned to the main menu"
menu ()

def moveBackward ():
fuel = 200
while fuel > 0:
feetBackward = input ("How many feet backward would you like to move?:")
obstacle = input ("How many feet behind you is the obstacle?:")

if feetBackward > fuel:
print "This is an invalid entry, you will now be returned to the main menu."
menu()

if feetBackward > obstacle:
feetBackward = feetBackward - obstacle
print "Your path is blocked, you will only be able to move ",feetBackward,"feet backward."

else:
"you will now move ",feetBackward,"feet backward."

while fuel > 0:
fuel = fuel - feetBackward
print "You have ",fuel,"fuel remaining."
feetForward = 0
obstacle = 0
menu ()
while fuel < 0:
print "You do not have enough fuel to move, you will now be returned to the main menu"
menu ()

main ()
 
Back
Top Bottom