Exercise

See Appendix A for an answer to the following exercise:

  1. [25] Make a program that will repeatedly ask the user to guess a secret number from 1 to 100 until the user guesses the secret number. Your program should pick the number at random by using the magical formula int(1 + rand 100).[261] When the user guesses wrong, the program should respond “Too high” or “Too low.” If the user enters the word quit or exit, or if the user enters a blank line, the program should quit. If the user guesses correctly, the program should quit then as well.

[261] See what the perlfunc manpage says about int and rand if you’re curious about these functions.

Get Learning Perl, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.