Hello, I'm extremely new to programming and have been assigned this project for school. I'm at a point where I've become a little confused and was curious if any of you guys could point me in the right direction.
Where I am running into problems is in the move_forward(fuel) module. It computes the total for fuel but doesn't return it to the global variable. What is weird to me is the fire_wep(ammo) module, which visually looks almost identical to move_forward(fuel), works just fine and returns the deducted amount.
Any help is much appreciated.Code:def main(): ammo = 5 fuel = 200 print'This will give you control of your battlebot' print print'Menu Selections:' print'Enter 1 to Fire Weapon' print'Enter 2 to Move Forward' print'Enter 3 to Move Backwad' print'Enter 4 to Exit' choice(ammo, fuel) def choice(ammo, fuel): print'Total amount of ammunition left',ammo print'Total amount of fuel left: ',fuel menu_choice = 0 while menu_choice != 4: print menu_choice = input('Enter your choice of action: ') if menu_choice == 1: ammo = fire_wep(ammo) elif menu_choice == 2: move_forward(fuel) elif menu_choice == 3: move_backward() def fire_wep(ammo): print ammo while ammo >= 1: print print'This is the amount of ammunition you have left',ammo distance = input('How far away is the target? ') if distance <= 20: print'The opponent is destroyed' elif distance <= 40: print'The opponent is partial disabled' elif distance >= 41: print'The opponent has not been damaged, get closer' ammo = ammo -1 return ammo while ammo == 0: print'out of ammo' def move_forward(fuel): feet = 0 print fuel while fuel >= 1: print print'This is how much fuel you have left',fuel feet = input('Enter how may feet forward you want to move: ') if feet <= fuel: print'You have moved forward',feet elif feet >= fuel: print'You do not have enough fuel to proceed that distance' print'Please enter a smaller value' fuel = fuel - feet print fuel return fuel else: print'You are out of fuel' main()
Thanks, moles
After sleeping on it, I figured it out. Forgot to set fuel = move_forward(fuel)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks