forked from Xyntax/corePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasyMath.py
More file actions
62 lines (49 loc) · 1.28 KB
/
Copy patheasyMath.py
File metadata and controls
62 lines (49 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'xy'
import random
import operator
ops = {'+': operator.add, '-': operator.sub}
MAXTRIES = 2
def doprob():
op = random.choice('+-')
nums = [random.randint(1, 10) for i in range(2)]
nums.sort(reverse=True)
ans = ops[op](*nums)
pr = '%d %s %d=' % (nums[0], op, nums[1])
print pr
oops = 0
while True:
try:
if int(raw_input()) == ans:
print 'correct'
break
if oops == MAXTRIES:
print 'answer : %s%s' % (pr, ans)
else:
print 'incorrect... try again'
oops += 1
except (KeyboardInterrupt, EOFError, ValueError):
print 'invalid input... try again'
def main():
while True:
doprob()
try:
opt = raw_input('Again? [y/n]').lower()
if opt and opt[0] == 'n':
break
except (KeyboardInterrupt, EOFError):
break
if __name__ == '__main__':
main()
'''
import random
import operator
random.choice()
random.randint()
nums = [random.randint(1, 10) for i in range(2)]
print 'answer : %s%s' % (pr, ans)
opt = raw_input('Again? [y/n]').lower() # mind this 'lower()'
if __name__ == '__main__':
main()
'''