79.0k views
3 votes
# Find highest score

def find_high_score(values):
high_score = 0

# Type your code here to call other functions and determine the highest score.

return high_score

# Add all occurrences of goal value
def check_singles(dice, goal):
score = 0

# Type your code here to calculate the sum of all values that match the parameter goal.

return score

# Check for three of a kind (score = 30)
def check_three_of_kind(dice):
score = 0

# Type your code here to check for three of a kind and assign the corresponding score.

return score

# Check for four of a kind (score = 40)
def check_four_of_kind(dice):
score = 0

# Type your code here to check for four of a kind and assign the corresponding score.

return score

# Check for five of a kind (score = 50)
def check_five_of_kind(dice):
score = 0

# Type your code here to check for five of a kind and assign the corresponding score.

return score

# Check for a full house (score = 35)
def check_full_house(dice):
score = 0

# Type your code here to check for a full house and assign the corresponding score.

return score

# Check for a straight (score = 45)
def check_straight(dice):
score = 0

# Type your code here to check for a straight and assign the corresponding score.

return score

if __name__ == '__main__':
# Do not modify
# Fill the array with five dice from input
dice = [int(val) for val in input().split()]

high_score = 0

# Place dice in ascending order
dice.sort()

# Find high score and output
high_score = find_high_score(dice)
print("High score:", high_score)

Program Specifications Write a program to calculate the score from a throw of five dice. Scores are assigned to different categories for singles, three of a kind, four of a kind, five of a kind, full house, and straight. Follow each step to gradually complete all functions.

Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.

User Shamith C
by
7.4k points

1 Answer

4 votes

Final answer:

The given code snippet is a program that calculates the score from a throw of five dice. It utilizes different functions to check for different combinations and assign scores accordingly. The final result is the highest score among all possible combinations.

Step-by-step explanation:

The given code snippet is a program that calculates the score from a throw of five dice. The program is divided into several functions that check for different combinations and assign scores accordingly. Here is a breakdown of the functions:

find_high_score(values)

This function takes in a list of dice values and returns the highest score among them. It utilizes the other functions to calculate the scores for different combinations and keeps track of the highest score.

check_singles(dice, goal)

This function takes in a list of dice values and a parameter goal and calculates the sum of all values that match the goal.

check_three_of_kind(dice)

This function checks if there are three dice with the same value and assigns a score of 30 if true.

check_four_of_kind(dice)

This function checks if there are four dice with the same value and assigns a score of 40 if true.

check_five_of_kind(dice)

This function checks if there are five dice with the same value and assigns a score of 50 if true.

check_full_house(dice)

This function checks if the dice values form a full house (three of a kind and a pair) and assigns a score of 35 if true.

check_straight(dice)

This function checks if the dice values form a straight (sequential values) and assigns a score of 45 if true.

By utilizing these functions, the program calculates the score based on the given dice values. The final result is the highest score among all possible combinations.

User Artem Svirskyi
by
8.4k points