Question: ( 1 5 marks ) Write a predicate to interactively guess an odd number from 2 0 0 0 to 4 0 0 0 in

(15 marks) Write a predicate to interactively guess an odd number from 2000 to 4000 in at most 6 tries. In case the user types an even number, the number of tries is reduced by an additional try. After each try, the number of remaining tries should be displayed. Outputs can be obtained with predicates write(X) and nl, and an input with the predicate read(X)(integer input will be followed by a .). The secret number should be hardcoded. For example: game . You have 6 t r i e s to gu e s s a number between 2000 and 40006. You have 4 t r i e s to gu e s s a number between 2000 and 40003001. The number i s l ow er ,3 t r i e s r em a in in g .2501. You gu e s s e d r i g h t . y e s .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!