单词游戏奖励单词中使用的字母。英文字母的频率越低,字母的得分越高。编写一个程序,要求用户输入一个单词。然后,程序应根据以下规则输出单词的分数:
如何为用户输入的字母添加分数?
我遇到了这个问题
#Letter Game Challenge
letters = ("e","a","r","i","o","t","n","s","l","c","u","d","p","m","h"
,"g","b","f","y","w","k","v","x","z","j","q")
points = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
,24,25,26)
def main():
global word_input
print ("Input a word to see the score")
word_input = input()
if any(letter in word_input for letter in letters):
l1()
else:
print ("Enter a word with letters in!")
main()
这就是我到目前为止还不知道如何分割输入的单词并检查一封信并为其分数。
答案 0 :(得分:0)
要遍历单词的字母,请使用for循环:
for letter in word_input:
您需要查找每个字母的分数。尝试使用字典:
scores = {"e": 1,
"a": 2,
#etc
然后你可以用scores[letter]