I'm writing a program for a class that's a game. It has ten places to put a peg, numbered 1-10. You have to roll 2 die and the summation is the number you have to work with to try and fill in the board.
So far, my program is as follows, but it's not working and if you have any hints then I would really appreciate it:
import random
#Global Constants
PEG_HOLE = 10
Pegged = "X"
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#Functions
#Rolls 2 six sided dice and returns sum
def roll_die():
roll1 = random.randrange(1,7)
roll2 = random.randrange(1,7)
total = (roll1) + (roll2)
return total
#initial hole list
def create_peg_holes():
print("-"*40)
for n in list1:
print("(" + str(n) + ")", end="")
print("\n" +("-"*40))
#Returns a list of numbers that are free to choose
def valid_moves(pegholes):
if list1[choice] != total:
return False
elif list1[choice-1]== "X":
return False
else:
return True
def ask_number(question, low, high):
low <= choice <= high
low = 0
high = 11
while total != 0:
append.choice("X")
total -= choice
total = int(total)
return number
def enter_peg(pegholes, roll, total):
if totalPegValue <= validMoves:
validMoves[totalPegValue] = "X"
while total != 0:
total -= totalPegValue
total = int(total)
return pegholes, pegholeList, move
else:
print ("Not valid")
###############
#Main Program
total = roll_die()
pegholes = create_peg_holes()
print(pegholes, "\n")
print("You rolled a ", total, "\n")
choice = input ("What hole do you choose? ")
choice = int(choice)
#validMoves = valid_moves(pegholes)
totalPegValue = 0
while totalPegValue != total:
pegholes[choice-1] = "X"
while totalPegValue < total:
pegholes, move = enter_peg(pegholes, total, totalPegValue)
totalPegValue += move
while choice <= total:
list1 = list1[:choice-1] + ["X"] + list1[choice:]
print(pegholes)