Issue (possible bug?) with Challenge: Sweet scores
Hello everyone,
as a python-newb, I would like to ask for some support with one of the challenges in Khan Academy, where I can't figure out what exactly I'm doing wrong - to be specific, step 2 of the exercise.
The task was as follows:
_________________________________________________________________________Aiyana added another fruit type to her game - cherry cards!
Every pair of cherry cards scores 5 points. For example, 0 or 1 cherries scores 0 points, 2 or 3 cherries score 5 points, 4 or 5 cherries score 10 points, and so on.
Add a new function definition get_cherry_score() that takes one parameter, the number of cherry cards.
Fill in the function body to return the correct score for the number of cherries.
Remember the // operator. You can calculate the number of pairs by floor dividing the number of cards by 2. The function should work for any positive number of cherry cards - even 47!
_________________________________________________________________________The solution I entered was:
def get_banana_score(num_bananas):
"""Returns a player's score based on the number of banana cards.
Bananas are worth more in bunches.
"""
if num_bananas == 1:
return 1
elif num_bananas == 2:
return 4
elif num_bananas >= 3:
return 10
else:
return 0
def get_apple_score(num_apples, has_poison_apple):
"""Returns a player's score based on the number of apple cards.
The poison apple card turns the apple score negative.
"""
if has_poison_apple is True:
return num_apples * -2
else:
return num_apples * 2
def get_cherry_score(num_cherrys):
pairs = (num_cherrys // 2)
return pairs * 5
def get_score(bananas, apples, has_poison_apple, cherrys):
"""Returns a player's total score based on their cards of each type."""
banana_score = get_banana_score(bananas)
apple_score = get_apple_score(apples, has_poison_apple)
cherry_score = get_cherry_score(cherrys)
return banana_score + apple_score + cherry_score
# Calculate the final score for each player.
player1_score = get_score(3, 2, True, 2)
player2_score = get_score(1, 5, False, 47)
print("Scores: p1=" + str(player1_score) + ", p2=" + str(player2_score))
_________________________________________________________________________When testing the result with different values, everything seems to work; however, the challenge menu still states that there is some issue with the code, even though I checked online for possible problems, but for all intents & purposes the solution I entered should be correct & I couldn't find an example where - to my understanding - the result was incorrect.
Does anyone here maybe see where I went wrong?
Thanks in advance for anyone who bothered reading through^^
Please sign in to leave a comment.