Skip to content

Instantly share code, notes, and snippets.

@RobinCPC
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinCPC/8961543 to your computer and use it in GitHub Desktop.
Save RobinCPC/8961543 to your computer and use it in GitHub Desktop.
how to make a warning to user if they input inappropriate value
#Using "raise" in python to warning user
def set(self, new_x, new_y, new_orientation):
if new_x < 0 or new_x >= world_size:
raise ValueError, 'X coordinate out of bound'
if new_y < 0 or new_y >= world_size:
raise ValueError, 'Y coordinate out of bound'
if new_orientation < 0 or new_orientation >= 2 * pi:
raise ValueError, 'Orientation must be in [0..2pi]'
self.x = float(new_x)
self.y = float(new_y)
self.orientation = float(new_orientation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment