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 _______
- 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).
-
knowledge = ["_"]*7
-
knowledge = ["_", "_", "_", "_", "_", "_", "_"]
-
knowledge = ["_"]*len(secret)
- Given the format of
knowledge, which of the following
is the best way to display this to the user playing the game?
-
print knowledge
-
print ' '.join(knowledge)
-
for k in range(len(knowledge)): print knowledge[k],
- 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)
- if
knowledge[i] is '_' then the user
hasn't guessed the letter at secret[i]
- if
knowledge[i] is NOT a '_' then the user
has guessed the letter at secret[i]
- if
secret[i] == secret[k] then
knowledge[i] == knowledge[k]
- What Python command can be used to break out of a
while True:
loop?
-
break
-
continue
-
goto end
- In playing Hangman, which should be checked
when the user enters a guess? (more than one is possible)
- That the guess is one letter long
- That the guess hasn't already been guessed before
- That the guess is a letter 'a'-'z'