Last active
August 29, 2015 13:56
-
-
Save RobinCPC/8961543 to your computer and use it in GitHub Desktop.
how to make a warning to user if they input inappropriate value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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