Problem 32

Twenty Questions... well, actually just Two

Make a program which plays a simple game of 20 2 Questions. The first question should be “animal, vegetable, or mineral?” Then, the second question should be “is it bigger than a breadbox?” Then, display one of six possible responses, depending on their answers. You can choose what answers to give for each of the six possibilities.

Here’s a suggestion:

size \ type:              |    animal      vegetable       mineral
--------------------------|--------------|-------------|------------
smaller than a shoebox:   |    squirrel    carrot          paper clip
bigger than a shoebox:    |    moose       watermelon      Camaro

You will use nested if statements to do this.

TWO QUESTIONS!
Think of an object, and I'll try to guess it.

Question 1) Is it animal, vegetable, or mineral?
> animal

Question 2) Is it bigger than a breadbox?
> no

My guess is that you are thinking of a mouse.
I would ask you if I'm right, but I don't actually care.
TWO QUESTIONS!
Think of an object, and I'll try to guess it.

Question 1) Is it animal, vegetable, or mineral?
> mineral

Question 2) Is it bigger than a breadbox?
> yes

My guess is that you are thinking of a truck.
I would ask you if I'm right, but I don't actually care.
TWO QUESTIONS!
Think of an object, and I'll try to guess it.

Question 1) Is it animal, vegetable, or mineral?
> vegetable

Question 2) Is it bigger than a breadbox?
> yes

You're thinking of a pumpkin!
I would ask you if I'm right, but I don't actually care.

◄ 31: A Frame with a Panel with Writing on It 33: Choose Your Own Adventure! ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.