-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram 5(a).rkt
75 lines (67 loc) · 2.96 KB
/
program 5(a).rkt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
;This program provides practice session for multiplication using speed mathematics skills.
;Program 5(a)
;Multiplying by factors
#lang racket
(printf "*(5(a))__________Multiplying by factors__________* \n")
;variable for storing score
(define score 0)
;list for storing questions pairs
(define lst (list ))
;list for storing answers
(define ans (list))
;list for storing index of wrong questions
(define wrng (list))
(define i 0)
(printf " Here is the list !! \n")
;10 sets of no. will be printed
(for ([i (in-range 0 10)])
;random nos. within range of 20-41 will be generated
(define-values (p q) (values (random 20 41) (random 20 41)))
;print the nos.
(printf "(~a) ~a * ~a \n"(+ i 1) p q)
;store the list of random pairs in list 'lst'
(set! lst (append lst (list p)(list q)))
);end of for
(printf " \n Your time starts now !!!\n" )
;note the starting time
(define start (current-seconds))
; now we will read the answers
(for ([i (in-range 0 10)])
(printf "(~a)"(+ i 1))
;get answer from user and store it in the variable x
(define x (read))
;add it to the list ans
(set! ans (append ans (list x)))
; check for the correct answer and increment the value of 'score' if input ans is true
(cond [(equal? x (*(list-ref lst (* i 2)) (list-ref lst (+ (* i 2) 1)) ))
(set! score (add1 score))
]
;if input answer is wrong then print false
[else
(set! wrng (append wrng (list (* i 2))))
];end of else
);end of cond
); end of for
; now time for evaluation
(printf "\n\n Time Taken = ~a sec\n"(- (current-seconds) start))
(printf "\n Score = ~a/10 \n" score)
(printf "\n Correct = ~a \n" score )
(printf "\n Incorrect = ~a \n" (- 10 score))
;Check if all the answers are correct
(cond [(equal? score 10)
(printf "*** Great!! all correct *** ")
]
;if incorrect answers != 0 , then print the correct answer
[else
(for ([i (in-range 0 (length wrng) )])
(printf "\n (~a) ~a * ~a = ~a || ~a \n "
(+(/(list-ref wrng i)2)1 )
(list-ref lst (list-ref wrng i ) )
(list-ref lst(+(list-ref wrng i ) 1))
(*(list-ref lst (list-ref wrng i ))
(list-ref lst(+ (list-ref wrng i ) 1)) )
(list-ref ans(/(list-ref wrng i )2))
);end of printf
);end of for
];end of else
);end of cond