Last active
May 28, 2022 18:27
-
-
Save s-praveen-kumar/0a0cbbe5241bcfbef05ead17c44f99cc to your computer and use it in GitHub Desktop.
Number Guessing Game using Common Lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun game () | |
(format t "GUESS THE NUMBER~%") | |
(let ((number (1+ (random 100 (make-random-state t))))) | |
(setq i 1) | |
(loop (format t "~:R trial~%" i) | |
(let ((guess (get-guess))) | |
(if (= number guess) (return) | |
(progn (if (> number guess) | |
(format t "Too Low~%") | |
(format t "Too High~%")) | |
(setq i (1+ i)) | |
)))) | |
(format t "Correct. You guessed in ~a attemptes~%" i) | |
)) | |
(defun get-guess () | |
(format t "Enter your guess between 1 to 100 : ") | |
(force-output) | |
(let ((guess (parse-integer (read-line) :junk-allowed t))) | |
(if (and (<= guess 100) (>= guess 0)) | |
guess (progn (format t "Invalid Guess~%") (get-guess))))) | |
(game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment