Closed Thread
Results 1 to 2 of 2

Thread: Returning a value

  1. #1
    moles is offline Newbie
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Returning a value

    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.

    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()
    Any help is much appreciated.
    Thanks, moles

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    moles is offline Newbie
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Re: Returning a value

    After sleeping on it, I figured it out. Forgot to set fuel = move_forward(fuel)

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Returning an array of strings
    By bbqroast in forum C and C++
    Replies: 6
    Last Post: 08-06-2011, 09:10 AM
  2. Help Returning a Hash
    By BlackMage in forum Java Help
    Replies: 0
    Last Post: 01-18-2010, 05:28 AM
  3. Switch Statements/returning value
    By melodia in forum C and C++
    Replies: 10
    Last Post: 11-16-2009, 09:18 PM
  4. returning values
    By Hot_Milo23 in forum Python
    Replies: 8
    Last Post: 10-13-2009, 07:27 AM
  5. Not returning Data
    By zeroradius in forum PHP Development
    Replies: 4
    Last Post: 01-30-2009, 03:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts