Compsci 101, Spring 2012, Feb. 23

By entering your name/net-id below you indicate you are in class on February 23 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 _______

  1. Suppose the code for playing Hangman uses a list to represent the current knowledge of the computer's secret word that the user is trying to guess and the length of the secret word is 7 letters. Which of the following is a good initialization for this list, to be stored in the variable knowledge (more than one may be correct).

    1. knowledge = ["_"]*7

    2. knowledge = ["_", "_", "_", "_", "_", "_", "_"]

    3. knowledge = ["_"]*len(secret)

  2. Given the format of knowledge, which of the following is the best way to display this to the user playing the game?

    1. print knowledge

    2. print ' '.join(knowledge)

    3. for k in range(len(knowledge)): print knowledge[k],

  3. Which of the following properly characterizes the relationship between knowledge and the variable secret that stores the word the user is trying to guess? (more than one can be correct)

    1. if knowledge[i] is '_' then the user hasn't guessed the letter at secret[i]

    2. if knowledge[i] is NOT a '_' then the user has guessed the letter at secret[i]

    3. if secret[i] == secret[k] then knowledge[i] == knowledge[k]

  4. What Python command can be used to break out of a while True: loop?

    1. break

    2. continue

    3. goto end

  5. In playing Hangman, which should be checked when the user enters a guess? (more than one is possible)

    1. That the guess is one letter long

    2. That the guess hasn't already been guessed before

    3. That the guess is a letter 'a'-'z'