-1
我正在做一個hang子手遊戲,並試圖創建一個函數,以 做到以下幾點;有關數學的基本python函數for循環
calculate_points(current_score,num_of_letter,letter_type):
現在的最新分數=你有多少分。你可以通過 來猜測正確的輔音點數, 這是字符串中每個字母+1點(例如:'蘋果',a ^^和 有人猜p,那會是+2點, 其輔音,但元音是一樣的形式,而你失去了點 -1每個字母。
CONSONANTS = 'bcdfghjklmnpqrstvwxyz'
VOWELS = 'aeiou'
字母類型可以是「C」或「c」的爲輔音,和「V」或「V」爲 元音。當前分數從0開始如此,current_score = 0,並且用戶 輸入他自己的分數,從0開始。
然後例如:
calculate_points(2,3,'C') (had 2 points, guessed 3 correct letters that are consonants so + 1 point per correct guess) 2+ 3=5
5
calculate_points(3,2,'V') (had 3 points, guessed 2 correct letters that are vowels so that is (-1) points per correct guess, so 3-2 =1
1
目前的嘗試:
def calculate_score(current_score,num_of_letter,letter_type):
new_score = 0
for i in range(0,len(CONSONTANTS)):
if CONSONANTS[i] == letter_type:
new_score = current_score + (num_of_letter*1)
for i in range(0,len(VOWELS)):
if VOWELS[i] == letter_type:
new_score = current_score + (num_of_letter*(-1))
return new_score
而問題是什麼? –