This is basically what I have. I've commented out all the places where I know what to do, but not how to do it.
PEG_HOLE = 10
PEGGED = "X"
#####################
# Functions you need to fill out
def roll_die():
# This function will simulate rolling two six sided dice
# and return the summation
return total
def create_peg_holes():
# This function createa the initial hole list, consisting of 10 numbers
return pegholes
def valid_moves(pegholes):
# This function will return a list of numbers, which are empty (don't
# have pegs in them), a.k.a., a list of valid moves
return validMoves
def print_peghole(pegholes):
# Print out the pegholes list in this manner:
"""
--------------------------------------------------
(1) (2) (3) (4) (5) (X) (7) (8) (X) (10)
--------------------------------------------------
"""
def ask_number(question, low, high):
#Ask for a number within a range.
# This function will read a number from the user, which is the number of
# the hole the user want to put the peg in.
# It will return an integer if the number is within range,
# low <= user_input <= high
# and keep looping if the user_input is out of range
def enter_peg(pegholes, roll, total):
# This function asks the user to choose a hole to place the peg
# It will check if the chosen_hole is valid, meaning:
# 1. it is not already pegged
# 2. the total number of all the holes user have chosen in this round
# is not larger than the roll. For example, if the user roll a 6,
# then, user cannot choose, 7/8/9/10 or any combinations that larger
# than 6, such as 2+5, 1+2+4, etc.
# If the chosen_hole is valid, peg the hole. Return both the pegholes list,
# and the move
# Hint: you need to call ask_number() and valid_moves() in this function.
return pegholes, move
#####################
# Main program begins here
#Create the empty peg board
pegholes = create_peg_holes()
#Print the peg board
print_peghole(pegholes)
#Until there are empty peg holes, roll the die
#If it is a losing game, the program will enter an infinite loop
#in the enter_peg function as there will be no valid moves
while valid_moves(pegholes):
rollValue = roll_die()
#Ask user to enter peg for each roll until
#totalPegValue in a round is equal to rollvalue
totalPegValue = 0
while totalPegValue < rollValue:
pegholes, move = enter_peg(pegholes, rollValue, totalPegValue)
#add the value of the move
totalPegValue += move
#print peg board with the new pegged hole
print_peghole(pegholes)
print("You Win.")
If anyone could help me figure out the commented places. I'd greatly appreciate it!