Skip to content

Instantly share code, notes, and snippets.

@hugs
Last active August 29, 2015 14:06
Show Gist options
  • Save hugs/4c4db98d9758c6a390ae to your computer and use it in GitHub Desktop.
Save hugs/4c4db98d9758c6a390ae to your computer and use it in GitHub Desktop.
Addition and Subtraction Practice Problems (Hundred Thousands)
from random import randint
problems = []
def print_problem(operation):
a = randint(100000, 999999)
b = randint(100000, 999999)
if b > a:
a,b = b,a
if operation == '+':
problems.append([a, '+', b, a+b])
else:
problems.append([a, '-', b, a-b])
print ' ' + str(a)
print ' ' + operation + ' ' + str(b)
print '---------'
print
print
print
print
def print_problems():
for i in range(20):
print_problem('+')
for i in range(20):
print_problem('-')
def print_answers():
for i, problem in enumerate(problems):
a, b, operation, answer = problem
print "%s)\t%s %s %s = %s" % (i+1, a, b, operation, answer)
print_problems()
print_answers()
637202
+ 548475
---------
675468
+ 300907
---------
453614
+ 346333
---------
864571
+ 645070
---------
963657
+ 575929
---------
876873
+ 205796
---------
987914
+ 527017
---------
280980
+ 175715
---------
974530
+ 920946
---------
742974
+ 647276
---------
458355
+ 142788
---------
724076
+ 707368
---------
953440
+ 336920
---------
426286
+ 161832
---------
846444
+ 761991
---------
748213
+ 371969
---------
805978
+ 361579
---------
321923
+ 223514
---------
759326
+ 180911
---------
994255
+ 485786
---------
659885
- 467965
---------
826137
- 587810
---------
950324
- 624251
---------
691827
- 510236
---------
776233
- 480633
---------
560039
- 472209
---------
343848
- 198914
---------
881397
- 272540
---------
961097
- 317186
---------
922946
- 868387
---------
501364
- 139945
---------
946527
- 185716
---------
253321
- 191069
---------
724147
- 372852
---------
418935
- 168315
---------
383380
- 289497
---------
879779
- 550128
---------
849045
- 516830
---------
557765
- 481229
---------
775684
- 105750
---------
1) 637202 + 548475 = 1185677
2) 675468 + 300907 = 976375
3) 453614 + 346333 = 799947
4) 864571 + 645070 = 1509641
5) 963657 + 575929 = 1539586
6) 876873 + 205796 = 1082669
7) 987914 + 527017 = 1514931
8) 280980 + 175715 = 456695
9) 974530 + 920946 = 1895476
10) 742974 + 647276 = 1390250
11) 458355 + 142788 = 601143
12) 724076 + 707368 = 1431444
13) 953440 + 336920 = 1290360
14) 426286 + 161832 = 588118
15) 846444 + 761991 = 1608435
16) 748213 + 371969 = 1120182
17) 805978 + 361579 = 1167557
18) 321923 + 223514 = 545437
19) 759326 + 180911 = 940237
20) 994255 + 485786 = 1480041
21) 659885 - 467965 = 191920
22) 826137 - 587810 = 238327
23) 950324 - 624251 = 326073
24) 691827 - 510236 = 181591
25) 776233 - 480633 = 295600
26) 560039 - 472209 = 87830
27) 343848 - 198914 = 144934
28) 881397 - 272540 = 608857
29) 961097 - 317186 = 643911
30) 922946 - 868387 = 54559
31) 501364 - 139945 = 361419
32) 946527 - 185716 = 760811
33) 253321 - 191069 = 62252
34) 724147 - 372852 = 351295
35) 418935 - 168315 = 250620
36) 383380 - 289497 = 93883
37) 879779 - 550128 = 329651
38) 849045 - 516830 = 332215
39) 557765 - 481229 = 76536
40) 775684 - 105750 = 669934
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment