Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Racket program that implements the following game. You ask your friend t

ID: 2246742 • Letter: W

Question

Write a Racket program that implements the following game.


You ask your friend to write down an integer between 1 and 100 but keep it hidden from you. You then execute your program which produces a guess for the number. If the guess is not correct, your friend tells you that the number is either BIGGER or SMALLER than this guess. You then execute the appropriate Racket function, either (BIGGER) or (SMALLER), and the computer computes another guess. Your code must guess the number within 6 attempts.

Explanation / Answer

#lang racket (define NUM 12) (define TRIES 6) (define CORRECT "Correct! Well guessed!") (define TOO_LOW "... Too Low ...") (define TOO_HIGH "... Too high ...") (define (num_message player_num) (if (= player_num NUM) CORRECT (if (> player_num NUM) TOO_HIGH TOO_LOW ) ) ) (define (number-guessing-game) (define out null) (for ([i (range TRIES)]) (set! out (num_message (read))) (print out) (when (equal? out CORRECT) (print "You won") (error "Exiting") ) ) (print "Too many attempts") ) (number-guessing-game)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote