1+ ;This program provides practice session for multiplication using speed mathematics skills.
12#lang racket
2- (define score 0 )
3- (for ([i '(1 2 3 4 5 )])
4- (define p (random 90 100 ))
5- (define q (random 90 100 ))
6- (printf " ~a * ~a \n " p q
7- )
8- (define x (read))
3+
4+ ;variable for storing score
5+ (define score 0 )
6+ ;list for storing questions pairs
7+ (define lst (list ))
8+ ;list for storing answers
9+ (define ans (list))
10+ ;list for storing index of wrong questions
11+ (define wrng (list))
12+
13+ (define i 0 )
14+ (printf " Here is the list !! \n " )
15+ ;10 sets of no. will be printed
16+ (for ([i (in-range 0 10 )])
17+ ;random nos. within range of 1-100 will be generated
18+ (define-values (p q) (values (random 1 100 ) (random 1 100 )))
19+ ;print the nos.
20+ (printf "(~a) ~a * ~a \n " (+ i 1 ) p q)
21+ ;store the list of random pairs in list 'lst'
22+ (set! lst (append lst (list p)(list q)))
23+ );end of for
924
10- (cond [(equal? x (* p q )) (printf "true :) \n " )
11-
12- +(set! score (add1 score) ) ]
13- [else (printf "false :( \n " )]
14- ))
15- (printf "\n**** your score = ~a/5 " score)
25+ (printf " \n Your time starts now !!!\n " )
26+ ;note the starting time
27+ (define start (current-seconds))
28+ ; now we will read the answers
29+ (for ([i (in-range 0 10 )])
30+ (printf "(~a) " (+ i 1 ))
31+
32+ ;get answer from user and store it in the variable x
33+ (define x (read))
34+ ;add it to the list ans
35+ (set! ans (append ans (list x)))
36+ ; check for the correct answer and increment the value of 'score' if input ans is true
37+ (cond [(equal? x (*(list-ref lst (* i 2 )) (list-ref lst (+ (* i 2 ) 1 )) ))
38+ (set! score (add1 score))
39+ ]
40+ ;if input answer is wrong then print false
41+ [else
42+ (set! wrng (append wrng (list (* i 2 ))))
43+ ];end of else
44+ );end of cond
45+ ); end of for
46+
47+ ; now time for evaluation
48+ (printf "\n\n Time Taken = ~a sec\n " (- (current-seconds) start))
49+ (printf "\n Score = ~a/10 \n " score)
50+ (printf "\n Correct = ~a \n " score )
51+ (printf "\n Incorrect = ~a \n " (- 10 score))
52+
53+
54+ ;Check if all the answers are correct
55+ (cond [(equal? score 10 )
56+ (printf "*** Great!! all correct *** " )
57+ ]
58+ ;if incorrect answers != 0 , then print the correct answer
59+ [else
60+ (for ([i (in-range 0 (length wrng) )])
61+ (printf "\n (~a) ~a * ~a = ~a || ~a \n "
62+ (+(/(list-ref wrng i)2 )1 )
63+ (list-ref lst (list-ref wrng i ) )
64+ (list-ref lst(+(list-ref wrng i ) 1 ))
65+ (*(list-ref lst (list-ref wrng i ))
66+ (list-ref lst(+ (list-ref wrng i ) 1 )) )
67+ (list-ref ans(/(list-ref wrng i )2 ))
68+ );end of printf
69+ );end of for
70+ ];end of else
71+ );end of cond
0 commit comments