Lesson 14.1. Additional exercises

Exercise 1

Write a program that draws a number at random between 0 and 100. The user must guess the number by making propositions. With each guess, the program tells the user if it is larger or smaller. Here is an example:

AI > I think of a number between 0 and 100, you have to find it.
Human > 50
AI > Too big!
Human > 25
AI > Too small!
Human > 35
AI > Too small!
Human > 42
AI > Bravo, you found in 4 shots!

Exercise 2

Write a program that queries the multiplication tables. The program will ask the multiplication again as long as the user's answer is wrong. When the user enters the correct answer, the program displays the time between the multiplication display and the correct answer. The program is exited by entering a negative number. At the end of the program, the average time is displayed:

8 x 1 = 8
You found in 1.4 seconds
8 x 6 = 40
8 x 6 = 48
You found in 11.9 seconds
7 x 9 = 64
7 x 9 = 63
You found in 11.9 seconds
9 x 9 = 81
You found in 3.1 seconds
3 x 0 = -1
 ==> Average response time: 7.1 seconds

See also


Last update : 12/06/2022