Python Forum
Python not correctly choosing numbers for my game.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python not correctly choosing numbers for my game.
#3
Sound like he trying to make Sudoku. 9 rows and 9 columns. Split into 3x3 grid.

1. I don't see enough code to suggest a fix.

2. Don't know GUI you are using? tkinter, pygame, wxpython, pyQt.

3. You need to learn to use containers. List or Dicts instead of making variables n1 to n9.
example. Your code simplified.
def Choose(self):
    for b in self.nb:
        possible = []
        for n in range(10):
            possible.append(True)

        if b.value == 0:
            for i in self.nb:
                if i.r == b.r:
                    possible[i.value] = False
                elif i.c == b.c:
                    possible[i.value] = False

            nlist = []
            for n in range(1,10):
                if possible[n]:
                    nlist.append(n)

            if len(nlist) == 1:
                b.value = nlist[0]
            elif len(nlist) > 1:
                b.value = random.choice(nlist)
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Python not correctly choosing numbers for my game. - by Windspar - Mar-29-2018, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  From python game in terminal to a website game using bottle Njanez 0 4,526 Aug-13-2021, 01:11 PM
Last Post: Njanez

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020