Any Python Programmers Out There??

OK, I do get it. (I think.) Code works now. Thank you and thanks to APL for the time you guys spent explaining it.

Now I'm ready to move on. The original problem in the book of puzzles was an 8 X 8 grid. Each horizontal line similar to my PLst: [2, 0, 4, 5, 7, 0, 3, 2] with some of the numbers in each line missing. Those are the ones I filled in with zero.

The challenge is to make each horizontal line AND each vertical line add to thirty. Well, I'll just type the entire puzzle.

[2, 0, 4, 5, 7, 0, 3, 2]
[0, 4, 1, 6, 0, 1, 9, 0]
[4, 0, 0, 1, 0, 8, 2, 4]
[1, 5, 0, 0, 5, 0, 0, 2]
[0, 6, 4, 3, 0, 4, 2, 6]
[7, 3, 4, 0, 2, 5, 1, 0]
[0, 1, 6, 7, 1, 0, 0, 2]
[1, 0, 2, 0, 3, 2, 5, 0]

So all sixteen lines have to add to thirty. Now that you've pointed me in the right direction, I'm going to forge ahead and attempt to finish the puzzle.

i assume you can't use numbers large than 9 in the grid?
 
we fucking know tom, your son said what I said like 40 hours ago at this point

It's Grind, Tom. :palm:

Ah well that would explain everything, obviously had a bad Xmas, did his mother force him to go to midnight Mass again?

My son explained in a clear easily understandable way without all the extraneous bullshit and need to have his ego massaged. He's thinking about writing a Python how-to guide in Japanese for his fellow workers at Softbank.
 
Last edited:
Ah well that would explain everything, obviously had a bad Xmas, did his mother force him to go to midnight Mass again?

My son explained in a clear easily understandable way [..bunch of shit no one cares about]

this is what your son said:

I contacted my son and he said this:
The variable I is the value inside the array, not its index

Hence it is wrong to write Plst

Instead it should be just I in the if statement



hmm where have we heard that before :bigthink:

OPs problem is doing the "if list == 0" conditional


Just do:

for item in list:
----if item == 0:
--------<other stuff goes here>

if list[item] == 0: <--- don't do this

rather than just simply using

if item == 0:

DO. NOT. USE. "if PLst == 0" Don't. STOP!

The conditional should be "if i == 0"


do so by doing if element == x. Not if list[element] == x.

his issue is wrongly trying to evaluate an element by doing if list[item] == 0
 
Do not make a separate variable names for the lists. I know it seems easier. I do that sometimes. There is an easier way.
 
Separate variable names is not needed.

PLst = [[2, 0, 4, 5, 7, 0, 3, 2],
[0, 4, 1, 6, 0, 1, 9, 0],
[4, 0, 0, 1, 0, 8, 2, 4],
[1, 5, 0, 0, 5, 0, 0, 2],
[0, 6, 4, 3, 0, 4, 2, 6],
[7, 3, 4, 0, 2, 5, 1, 0],
[0, 1, 6, 7, 1, 0, 0, 2],
[1, 0, 2, 0, 3, 2, 5, 0]]
 
Progress Report.

bubba lets all collectively do another puzzle. let me know when you have a new one

There'll be more puzzles, but for now I want to concentrate on this one.

Found this web site: https://discuss.python.org

Posted my question there last night. Included the code I had written. Two people responded. One said the reason I got the same numbers every time is because when the list is modified, there are no zeros in it. I start with

[2, 0, 4, 5, 7, 0, 3, 2] The function modifies it to
[2, 4, 4, 5, 7, 9, 3, 2]

That doesn't sum to thirty, so program send it through function again. But this time, it sends the MODIFIED list through. There are no zeros this time, so list never changes.

When I read that, I thought, "That is so obvious! Why didn't I see that?? I must be really dumb."

So I changed program:

ALst = [1, 2, 3, 4, 5, 6, 7, 8, 9] # Don't use `ALst.'
OldHLine0 = [2, 0, 4, 5, 7, 0, 3, 2]
OldHLine1 = [0, 4, 1, 6, 0, 1, 9, 0]
OldHLine2 = [4, 0, 0, 1, 0, 8, 2, 4]
OldHLine3 = [1, 5, 0, 0, 5, 0, 0, 2]
OldHLine4 = [0, 6, 1, 3, 0, 4, 2, 6]
OldHLine5 = [7, 3, 4, 0, 2, 5, 1, 0]
OldHLine6 = [0, 1, 6, 7, 1, 0, 0, 2]
OldHLine7 = [1, 0, 2, 0, 3, 2, 5, 0]
HLine1 = OldHLine1

def RShuf (ALst, HLst):
--- for I, Value in enumerate (HLst):
------- if Value == 0:
-------- HLst = random.randint (1, 9)

while sum (HLine1) != 30:
-- RShuf (ALst, HLine1)
----- if HLine1 != 30: # This `If' duplicates `While.'
------- HLine1 = OldHLine1 # Added it later.
--- print (HLine1, sum (HLine1))

I thought, "This will do the job. Problem solved!"

However, I'm even dumber than I thought. Still same result. Same digits repeated time after time after time.

So my progress is stalled. For now.
 
Back
Top