私は、本来の結果とは異なる結果をもたらす関数を持っています。これは、Python のスクラブル ゲーム用です。メソッドは次のとおりです-関数とそのさまざまなタイプ:
num = 0
length = (int(len(hand))/2) - 1
print('Current Hand: '),
print(displayHand(hand))
while (len(hand)>0):
lettersGuessed = raw_input('Enter word, or a "." to indicate that you are finished: ')
word= lettersGuessed
if (isValidWord(word, hand, wordList)==False):
print("Invalid word, please try again."+'\n')
if (isValidWord(word, hand, wordList)==True):
num += getWordScore(word, n)
length -= 1
updateHand(hand, word)
print('"'+word+'"'+" earned " +str(getWordScore(word, n))+" points. "+" Total: "+str(num)+'\n')
print('Current Hand: '),
print(displayHand(hand))
if (isValidWord(word, hand, wordList)==True):
num += getWordScore(word, n)
length -= 1
updateHand(hand, word)
print('"'+word+'"'+" earned " +str(getWordScore(word, n))+" points. "+" Total: "+str(num)+'\n')
if length>=1:
print('Current Hand: '),
print(displayHand(hand))
if (isValidWord(word, hand, wordList)==True):
num += getWordScore(word, n)
length -= 1
updateHand(hand, word)
print('"'+word+'"'+" earned " +str(getWordScore(word, n))+" points. "+" Total: "+str(num)+'\n')
# print('Current Hand: '),
# print(displayHand(hand))
if (length==0)&(isValidWord(word, hand, wordList)==False):
print("Run out of letters. Total score: "+str(num))
if (length==0):
print("Run out of letters. Total score: "+str(num))
break;
if (length==0)&(isValidWord(word, hand, wordList)==True):
print("Run out of letters. Total score: "+str(num))
break;
if (lettersGuessed =="."):
print("Goodbye! Total score: "+str(num))
break;
これが実行されたテストケースです。これは、上記の出力の結果であるはずのテスト ケースですが、そうではありません。
誰でも私のコードの何が問題なのか見てもらえますか?
関数呼び出し:
wordList = loadWords()
playHand({'w':1, 's':1, 't':2, 'a':1, 'o':1, 'f':1}, wordList, 7)
Output:
Current Hand: a s t t w f o
Enter word, or a "." to indicate that you are finished: tow
"tow" earned 18 points. Total: 18 points
Current Hand: a s t f
Enter word, or a "." to indicate that you are finished: tasf
Invalid word, please try again.
Current Hand: a s t f
Enter word, or a "." to indicate that you are finished: fast
"fast" earned 28 points. Total: 46 points.
Run out of letters. Total score: 46 points.
と言う代わりにRun out of letters. Total score: 46.
、次のように言っています。
Current Hand:
None
Run out of letters. Total score: 46
コードを削除するにはどうすればよいですか:
Current Hand:
None
誰かが私のコードをコピーして、さまざまなテストケースの文字を手に入れてもらえますか?