Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-25-2009, 09:15 PM   #1
In Runtime
 
Join Date: Sep 2005
Posts: 349
Default Python Programmers

*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.

Quote:
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 ()
__________________
Check out this url, its not a scam you really do make money, i've been a part of it for a month and have made $30+ . http://www.treasuretrooper.com/245769
Also check out my Imeem http://infin1ty.imeem.com
Infin1ty is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:50 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0