PDA

View Full Version : Help with Python


Cursecoin
08-05-2009, 11:52 AM
# -*- coding: cp1252 -*-
#Lab Practicum
#IT 104
#Battlebot 1.0


#Fire weapon command



def main():
choice = 0

fuel = 200

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

choice = input ("Enter Your Selection:")
if choice == 1:
fire_again='y'
while fire_again == 'y':
target_distance = input ("How far (in feet) is the opponent battlebot?")
for ammo in range (6, 1):
if target_distance <= 20:
print ("The target is destroyed!!!")

elif target_distance <= 40:
print ("The target is partially disabled.")
else:
print ("The target is unharmed.")
ammo = ammo - 1
print'you have',ammo,'shots left'
if ammo == 0:
print ("You have no more ammo")
main()
else:
fire_again = raw_input ("Would you like to fire again? Type y or n.")
if choice == 2:
movement(fuel)


elif choice == 3:
movement2(fuel)
elif choice == 4:
Print ("Goodbye.")
else:
print ("Invalid input- Please Try Again.")




#movement command (forward)

def movement(fuel):

distance = input ("Enter how far you want to go (in feet):")
obstacle = input ("How far (in feet) are any obstacles in your path:")
new_distance = distance

if obstacle < distance and obstacle > 0:
print 'There is an obstacle in your path. You can only move',obstacle,' feet.'
new_distance= distance - obstacle
else:
print "You can move the entire distance of", distance," feet."
fuel = fuel - new_distance
print 'Fuel currently at',fuel
if fuel<=0:
print'You have no more fuel.'


#movement command (backward
def movement2(fuel):
distance = input ("Enter how far you want to go (in feet):")
obstacle = input ("How far (in feet) are any obstacles in your path:")
new_distance =distance

if obstacle < distance:
print 'There is a obstacle in your path. You can only move',obstacle,'feet.'
new_distance=obstacle

else:
print ("You can move the entire distance of", distance,'feet.')

fuel = fuel - new_distance
print'Fuel currently at',fuel
if fuel<=0:
print 'You have no more fuel'






#def fire_weapon(ammo):





#Move forward command

#def move_forward(fuel):


#Move backward command

#def move_backward(fuel):

# return newFuel


#main menu
main()