Compsci 101, Spring 2012, Feb. 9

By entering your name/net-id below you indicate you are in class on February 9 to answer these questions and that you have answered them. Your name should not appear unless you are in class when answering these questions.
Name_________________   net-id _______   Name_________________   net-id _______


Name_________________   net-id _______   Name_________________   net-id _______

    These questions are based on the code GuessNumber.py

  1. Which of the following is true about the variables answer and guess and their respective values assigned before the loops in the functions play_game_computerguess and play_game_humanguess, respectively?

    1. The initializations ensure that each loop will be entered the first time -- the actual values used: 'none' and -1 ensure the loops will be entered.

    2. Python requires initializing variables and any values could have been used, there's nothing special about 'none' and -1 that are used.

    3. It would be better to ask the user to initialize the variables before the loop using raw_input.

  2. About how many guesses will be needed by the computer to guess the user's secret number when it's between 1 and 1000?

    1. 10

    2. 100

    3. 512

  3. In the loop-body of function play_game_humanguess there's no code to process the return value "correct" returned by get_status. Which is the best explanation for why no code is needed to process this return value?

    1. When there's no elif or else to handle a case Python will automatically generate code to handle it.

    2. The loop guard: secret != guess handles the case of a correct guess and it's the code executed after the elif.

    3. Because there's no code for "correct" this means that the number of guesses reported is wrong after the loop finishes.