Created
May 21, 2015 12:05
-
-
Save junmakii/a7f2e1ba1ec0c796e62d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/python | |
| #-*- coding: utf-8 -*- | |
| from __future__ import print_function, division | |
| import os, sys, random | |
| def get_statement(): | |
| x = random.randint(1, 99) | |
| y = random.randint(1, 99) | |
| arithmetic_operators = ['+', '-', '/', '*'] | |
| arithmetic_operator = arithmetic_operators[random.randint(0, len(arithmetic_operators) - 1)] | |
| statement = '%d %s %d' % (x, arithmetic_operator, y) | |
| return statement | |
| def method(): | |
| statement = get_statement() | |
| data = raw_input('%s: ' % statement) | |
| if filter(lambda x: data == x, ['q', 'quit']): | |
| sys.exit(0) | |
| result = eval(statement) | |
| print(result) | |
| def main(argv): | |
| do_loop = True | |
| while do_loop: | |
| try: | |
| method() | |
| except Exception as err: | |
| print(err, file=sys.stderr) | |
| return 0 | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment