Skip to content

Commit b30a920

Browse files
authored
Merge pull request #1 from arushi-bhatt/master
Syncing from original
2 parents 59d4c18 + d48a9af commit b30a920

2 files changed

Lines changed: 111 additions & 13 deletions

File tree

multiply.bak

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
;This program provides practice session for multiplication using speed mathematics skills.
2+
#lang racket
3+
4+
;variable for storing score
5+
(define score 0)
6+
(define lst (list ))
7+
(define wrng (list))
8+
(define i 0)
9+
10+
;10 sets of no. will be printed
11+
(for ([i (in-range 1 6)])
12+
;random nos. within range of 1-100 will be generated
13+
(define-values (p q) (values (random 1 100) (random 1 100)))
14+
15+
16+
;print the nos.
17+
(printf "(~a) ~a * ~a \n"i p q)
18+
;gets answer from user and store it in the variable x
19+
20+
(define x (read))
21+
(set! lst (append lst (list p)(list q)(list x)))
22+
; checks for the correct answer and increment the value of 'score' if input ans is true
23+
(cond [(equal? x (* p q )) (set! score (add1 score))]
24+
;if input answer is wrong then print false
25+
[else (set! wrng (append wrng (list (* i 3))))]
26+
)
27+
)
28+
29+
(printf "\n**** your score = ~a/5 \n" score) ;print your score
30+
(printf "\n**** correct = ~a \n" score )
31+
(printf "\n**** incorrect = ~a \n" (- 5 score))
32+
(cond [(equal? (- 5 score) 0) (printf "*** Great!! all correct *** ") ]
33+
34+
[else (for ([i (in-range 0 (length (wrng)) )])
35+
(printf "~a * ~a = ~a || ~a \n "
36+
(list-ref lst (list-ref wrng i ) )
37+
(list-ref lst(+ (list-ref wrng i ) 1))
38+
(* (list-ref lst (list-ref wrng i ) ) (list-ref lst(+ (list-ref wrng i ) 1))
39+
)
40+
(list-ref lst(+ (list-ref wrng i ) 2)))
41+
)]
42+
)

multiply.rkt

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,71 @@
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

Comments
 (0)