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)

please put your code in (CODE) before posting it. Specially in this case, python code!!!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

How do I put it in (CODE)? Sorry, but this is my first time using this site.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

click on (CODE) on the icon above text area and put your code in between the code-tags.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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()
#validMoves = valid_moves(pegholes)

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
                                
#if valid_moves(pegholes) == True:
while valid_moves(pegholes):
    totalPegVale = 0
    while totalPegValue < total:
        pegholes, choice = enter_peg(pegholes, rollValue, totalPegValue)
        totalPegValue += choice
        print_peghole(pegholes)

while valid_moves(True):
    list1 = list1[:choice-1] + ["X"] + list1[choice:]
    print("-"*40)
    for n in list1:
        print("(" + str(n) + ")", end="")
    print("\n" +("-"*40))
    break

I worked on it some more, but it still isn't working correctly.

so, let's go one by one, first

of all, line 21,

print("(" + str(n) + ")", end="")

what do you mean by end="" ???

next, line56

pegholes = create_peg_holes()

create_peg_holes() is not returning anything, what do you expect to be in pegholes variable????

This question has already been answered. Start a new discussion instead.