检查点
支持重复字母
学习如何评估重复输入。
1#test_word_info.rb 2 3require_relative 'word_info' 4 5puts word_info('palladium', ['p']) 6puts word_info('palladium', ['p', 'l']) 7puts word_info('palladium', ['p', 'l', 'a'])
1root@educative:/usercode# ruby hangman.rb 2P _ _ _ _ _ _ _ _ 3P _ L _ _ _ _ _ _ 4P A L _ _ _ _ _ _
1# letters 应当是给定单词中的一部分,并且为小写 2def word_info word, letters 3 4 n = word.length 5 underscores = "_ " * n 6 7 letters.each do |letter| 8 i = word.index(letter) 9 underscores[2 * i] = letter.upcase 10 end 11 12 underscores 13 14end
1root@educative:/usercode# ruby hangman.rb 2P _ _ _ _ _ _ _ _ 3P _ L L _ _ _ _ _ 4P A L L A _ _ _ _
Quiz
单选题
这段代码输出 "3" 的原因是:
1 / 2