Skip to content

Commit 781230e

Browse files
committed
added Exercise/Message step to multiplication table exercise
catches wrong solution where `*` is used instead of `x`
1 parent 88e5c3d commit 781230e

File tree

2 files changed

+1445
-0
lines changed

2 files changed

+1445
-0
lines changed

core/chapters/c08_nested_loops.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,181 @@ def program(self):
416416
def check(self):
417417
return "TypeError: unsupported operand type(s) for +: " in self.result
418418

419+
class used_times_instead_of_x(ExerciseStep, MessageStep):
420+
"""
421+
That's almost correct! Make sure to display the right character `x` in your table.
422+
For example, your solution should display `3 x 4 = 12` and not `3 * 4 = 12`.
423+
"""
424+
425+
def solution(self):
426+
for left in range(12):
427+
left += 1
428+
for right in range(12):
429+
right += 1
430+
print(f'{left} * {right} = {left * right}')
431+
print('----------')
432+
433+
tests = {
434+
(): """\
435+
1 * 1 = 1
436+
1 * 2 = 2
437+
1 * 3 = 3
438+
1 * 4 = 4
439+
1 * 5 = 5
440+
1 * 6 = 6
441+
1 * 7 = 7
442+
1 * 8 = 8
443+
1 * 9 = 9
444+
1 * 10 = 10
445+
1 * 11 = 11
446+
1 * 12 = 12
447+
----------
448+
2 * 1 = 2
449+
2 * 2 = 4
450+
2 * 3 = 6
451+
2 * 4 = 8
452+
2 * 5 = 10
453+
2 * 6 = 12
454+
2 * 7 = 14
455+
2 * 8 = 16
456+
2 * 9 = 18
457+
2 * 10 = 20
458+
2 * 11 = 22
459+
2 * 12 = 24
460+
----------
461+
3 * 1 = 3
462+
3 * 2 = 6
463+
3 * 3 = 9
464+
3 * 4 = 12
465+
3 * 5 = 15
466+
3 * 6 = 18
467+
3 * 7 = 21
468+
3 * 8 = 24
469+
3 * 9 = 27
470+
3 * 10 = 30
471+
3 * 11 = 33
472+
3 * 12 = 36
473+
----------
474+
4 * 1 = 4
475+
4 * 2 = 8
476+
4 * 3 = 12
477+
4 * 4 = 16
478+
4 * 5 = 20
479+
4 * 6 = 24
480+
4 * 7 = 28
481+
4 * 8 = 32
482+
4 * 9 = 36
483+
4 * 10 = 40
484+
4 * 11 = 44
485+
4 * 12 = 48
486+
----------
487+
5 * 1 = 5
488+
5 * 2 = 10
489+
5 * 3 = 15
490+
5 * 4 = 20
491+
5 * 5 = 25
492+
5 * 6 = 30
493+
5 * 7 = 35
494+
5 * 8 = 40
495+
5 * 9 = 45
496+
5 * 10 = 50
497+
5 * 11 = 55
498+
5 * 12 = 60
499+
----------
500+
6 * 1 = 6
501+
6 * 2 = 12
502+
6 * 3 = 18
503+
6 * 4 = 24
504+
6 * 5 = 30
505+
6 * 6 = 36
506+
6 * 7 = 42
507+
6 * 8 = 48
508+
6 * 9 = 54
509+
6 * 10 = 60
510+
6 * 11 = 66
511+
6 * 12 = 72
512+
----------
513+
7 * 1 = 7
514+
7 * 2 = 14
515+
7 * 3 = 21
516+
7 * 4 = 28
517+
7 * 5 = 35
518+
7 * 6 = 42
519+
7 * 7 = 49
520+
7 * 8 = 56
521+
7 * 9 = 63
522+
7 * 10 = 70
523+
7 * 11 = 77
524+
7 * 12 = 84
525+
----------
526+
8 * 1 = 8
527+
8 * 2 = 16
528+
8 * 3 = 24
529+
8 * 4 = 32
530+
8 * 5 = 40
531+
8 * 6 = 48
532+
8 * 7 = 56
533+
8 * 8 = 64
534+
8 * 9 = 72
535+
8 * 10 = 80
536+
8 * 11 = 88
537+
8 * 12 = 96
538+
----------
539+
9 * 1 = 9
540+
9 * 2 = 18
541+
9 * 3 = 27
542+
9 * 4 = 36
543+
9 * 5 = 45
544+
9 * 6 = 54
545+
9 * 7 = 63
546+
9 * 8 = 72
547+
9 * 9 = 81
548+
9 * 10 = 90
549+
9 * 11 = 99
550+
9 * 12 = 108
551+
----------
552+
10 * 1 = 10
553+
10 * 2 = 20
554+
10 * 3 = 30
555+
10 * 4 = 40
556+
10 * 5 = 50
557+
10 * 6 = 60
558+
10 * 7 = 70
559+
10 * 8 = 80
560+
10 * 9 = 90
561+
10 * 10 = 100
562+
10 * 11 = 110
563+
10 * 12 = 120
564+
----------
565+
11 * 1 = 11
566+
11 * 2 = 22
567+
11 * 3 = 33
568+
11 * 4 = 44
569+
11 * 5 = 55
570+
11 * 6 = 66
571+
11 * 7 = 77
572+
11 * 8 = 88
573+
11 * 9 = 99
574+
11 * 10 = 110
575+
11 * 11 = 121
576+
11 * 12 = 132
577+
----------
578+
12 * 1 = 12
579+
12 * 2 = 24
580+
12 * 3 = 36
581+
12 * 4 = 48
582+
12 * 5 = 60
583+
12 * 6 = 72
584+
12 * 7 = 84
585+
12 * 8 = 96
586+
12 * 9 = 108
587+
12 * 10 = 120
588+
12 * 11 = 132
589+
12 * 12 = 144
590+
----------
591+
"""
592+
}
593+
419594
tests = {
420595
(): """\
421596
1 x 1 = 1

0 commit comments

Comments
 (0)