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!

[import random

PEG_HOLE = 10

PEGGED = "X"

pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

def roll_die():
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
total = (dice1 + dice2)
return total

def create_peg_holes():
pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
return pegholes

def valid_moves(pegholes):
validMoves = pegholes
validMoves.remove(PEGGED)
for i in validMoves:
if validMoves != 0:
return validMoves

def print_peghole(pegholes):
print("--------------------------------------------------")
for i in pegholes:
print("", pegholes[i-1], sep="(", end=") ")
print("\n--------------------------------------------------")

def ask_number():
user_input = int(input("Which peg do you want to put in(1-10)?:"))
if user_input < 1:
print("That is not an option.")
elif user_input > 10:
print("That is not an option.")
elif user_input > 1:
print("You placed a peg on space", user_input,"!")
pegholes.remove(user_input)
pegholes.insert(user_input-1, PEGGED)
else:
print("That is not an option.")
return pegholes]

This is what I've gotten so far. But I'm not sure if these def will work.

How about a more specific question? How would I go about printing pegholes when the list not includes PEGGED which is == to "X"? When I try to print with no PEGGED variables in my list, I'm given a pretty list of everything in pegholes, but as soon as PEGGED is included I get an error message reading:
[Traceback (most recent call last):
File "<pyshell#196>", line 1, in <module>
enter_peg(pegholes, roll_die)
File "/Users/Brett/Desktop/A201/bwbyron_A8.py", line 57, in enter_peg
return print_peghole(pegholes)
File "/Users/Brett/Desktop/A201/bwbyron_A8.py", line 29, in print_peghole
print("", pegholes[i-1], sep="(", end=") ")
TypeError: unsupported operand type(s) for -: 'str' and 'int']

What should I do about this?

[import random

PEG_HOLE = 10

PEGGED = "X"

pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
total = (dice1 + dice2)


def roll_die():
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
total = (dice1 + dice2)
return total

def create_peg_holes():
pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
return pegholes

def print_peghole(pegholes):
print("--------------------------------------------------")
print("", pegholes, sep="(", end=") ")
print("\n--------------------------------------------------")

def ask_number(pegholes):
x = 0
while x != 1:
user_input = int(input("Which peg do you want to put in(1-10)?:"))
if user_input in pegholes:
print("That is a valid move.")
return user_input
x += 1
else:
print("That is not a valid move.")


def enter_peg(pegholes, roll_die):

total = roll_die()
total = int(total)
print(total)
while total != 0:
user_input = int(input("Which peg do you want to put in(1-10)?:"))
if user_input in pegholes:
print("You placed a peg on space", user_input,"!")
pegholes.remove(user_input)
pegholes.insert(user_input-1, PEGGED)
total -= user_input
else:
print("That is not a valid move.")
return print_peghole(pegholes)


while pegholes:
rollValue = total
enter_peg(pegholes, rollValue)
totalPegValue = 0
while totalPegValue < rollValue:
pegholes = enter_peg(pegholes, rollValue)
pegholes
print("You win!")]

This is what I came up with, but it only loops three times and then gives me an error message. What is the problem?

import random

PEG_HOLE = 10

PEGGED = "X"

pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
total = (dice1 + dice2)


def roll_die():
   dice1 = random.randint(1,6)
   dice2 = random.randint(1,6)
   total = (dice1 + dice2)
   return total

def cpeg_holes():
   pegholes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
   return pegholes



def print_peghole(pegholes):
  print("--------------------------------------------------")
  print("", pegholes, sep="(", end=") ")
  print("\n--------------------------------------------------")

def ask_number(pegholes):
   x = 0
   while x != 1:
      user_input = int(input("Which peg do you want to put in(1-10)?:"))
      if user_input in pegholes:
          print("That is a valid move.")
          return user_input
          x += 1
      else:
          print("That is not a valid move.")


def enter_peg(pegholes, roll_die):

   total = roll_die()
   total = int(total)
   print(total)
   while total != 0:
      user_input = int(input("Which peg do you want to put in(1-10)?:"))
      if user_input in pegholes:
           print("You placed a peg on space", user_input,"!")
           pegholes.remove(user_input)
           pegholes.insert(user_input-1, PEGGED)
           total -= user_input
      else:
          print("That is not a valid move.")
   return print_peghole(pegholes)




while pegholes:
   rollValue = total
   enter_peg(pegholes, rollValue)
   totalPegValue = 0
   while totalPegValue < rollValue:
       pegholes = enter_peg(pegholes, rollValue)
       pegholes
print("You win!")[/code]
This is what I came up with, but it only loops three times and then gives me an error message. What is the problem? 

Do not forget to push CODE before pasting code!

Edited 3 Years Ago by Dani: Formatting fixed

You are giving rollValue to enter_peg as function name to call at line 45 even it is getting value of total, which is given value of total value of dice, an integer.

This article has been dead for over six months. Start a new discussion instead.