The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
School Project in Python
Posted by: Xenrutcon | May 27, 2009 @ 8:16pm
Python Code
[
Download
]
#Robot Battlebot #Notice the debug and testing codes :) def main(): menu = 0 fuel = 200 ammo = 5 while menu != 6: print 'Menu Selections:' print #blank print '1 - Fire' print '2 - Forward' print '3 - Back' print '4 - Ammo' print '5 - Fuel' print '6 - Exit' print #blank print 'Enter your selection as 777 to reset all values' print #blank menu = input('Enter your selection: ') if menu == 1: ammo = fireWeapon(ammo) elif menu == 2: fuel = moveForward(fuel) elif menu == 3: fuel = moveBackward(fuel) elif menu == 4: print #blank print 'You have',ammo,'shot(s) left' print #blank elif menu == 5: print #blank print 'You have',fuel,'unit(s) of fuel left' print #blank elif menu == 6: print 'Goodbye' elif menu == 1337: print #blank print 'ACCESS GRANTED' print 'POWERING UP' print #blank ammo = ammo + 200 fuel = fuel + 100000 elif menu == 666: print #blank print '*' print '**' print '***' print '****' print '*****' print '??????' print '*****' print '****' print '***' print '**' print '*' print #blank ammo = 0 fuel = 0 elif menu == 777: print #blank print 'Reset' print #blank ammo = 5 fuel = 200 else: print #blank print 'Invalid selection' print #blank def fireWeapon(ammo): if ammo > 0: ammo = ammo - 1 print #blank print 'Weapon loaded' print #blank fireRange = input('Input distance to enemy in feet: ') if fireRange <= 20: print #blank print 'Enemy destroyed' print 'You have',ammo,'shot(s) left' print #blank elif fireRange > 20 and fireRange <= 40: print #blank print 'Enemy disabled' print 'You have',ammo,'shot(s) left' print #blank elif fireRange > 40: print #blank print 'You missed!' print 'You have',ammo,'shot(s) left' print #blank else: print #blank print 'You are out of ammo' print #blank return ammo def moveForward(fuel): if fuel >= 1: fDistance = input('Input move distance in feet: ') if fDistance > fuel: print #blank print 'Not enough fuel. The robot has',fuel,'unit(s) of fuel left' print #blank else: fObs = input('Input distance to obstacle in feet: ') fBlock = fObs - 1 if fDistance >= fObs: print #blank print 'The obstacle is blocking your path' print 'You can move',fBlock,'feet before hitting the obstacle' print #blank else: print #blank print 'Move successful!' fuel = fuel - fDistance print 'You moved forward',fDistance,'feet and have',fuel,'unit(s) of fuel left' print #blank else: print #blank# print 'You are out of fuel' print #blank# return fuel def moveBackward(fuel): if fuel >= 1: bDistance = input('Input move distance in feet: ') if bDistance > fuel: print #blank print 'Not enough fuel. The robot has',fuel,'unit(s) of fuel left' print #blank else: bObs = input('Input distance to obstacle in feet: ') bBlock = bObs - 1 if bDistance >= bObs: print #blank print 'The obstacle is blocking your path' print 'You can move',bBlock,'feet before hitting the obstacle' print #blank else: print #blank print 'Move successful!' fuel = fuel - bDistance print 'You moved backward',bDistance,'feet and have',fuel,'unit(s) of fuel left' print #blank else: print #blank print 'You are out of fuel' print #blank return fuel main()
Syntax Highlighting
[
Open in new window
]
Author Comments
Code was a final practicum for my introduction to programming class. I enjoy python and even added "debugging" codes for kicks :)
Rating
4.52 / 8
147 Votes