+ 3

Please help me in Python.

https://code.sololearn.com/c9r4xKb9576V/?ref=app This is a sudoku validator, the block rule isn't applied yet. There is a mistake in the first row of it, that 3 is repeated. I was just testing it to check if it is working fine in checking the rows and columns but what the output comes is so abnormal. Can you please check it and tell me where's the mistake.

23rd May 2019, 6:58 AM
Abdul S Ansari
Abdul S Ansari - avatar
7 Antworten
+ 5
Change lines 20-39 for this. for z in range(9): #Row check if point == sudoku[x][z]: cir += 1 #Column check if point == sudoku[z][y]: cic += 1 if cic >= 2: print(f'{point} in column {y+1} is repeated.') ch = False if cir >= 2: print(f'{point} in row {x+1} is repeated.') ch = False cir = cic = 0 if ch != False: return "This is a valid sudoku." else: return "This is not a valid sudoku"
23rd May 2019, 12:30 PM
Diego
Diego - avatar
+ 3
Samad Sama Remove one level of indentation in lines 27-33. Change if cir >= 2: to if cir >= 2: and so on.
24th May 2019, 3:44 AM
Diego
Diego - avatar
+ 3
Samad Sama 1. It's not working because the initial value of ch is 0, which equals False. 2. It won't print the mistakes because there aren't.
24th May 2019, 3:58 AM
Diego
Diego - avatar
+ 2
Diego Oh yeah! It worked! It worked! Thank you so much
24th May 2019, 4:06 AM
Abdul S Ansari
Abdul S Ansari - avatar
+ 2
Once you decided on Numpy array you might use specific count and slicing methods.
24th May 2019, 4:14 PM
tamaslud
tamaslud - avatar
+ 1
Diego Thank you But now this code is just verifying the sudoku and not telling the mistakes in it.
24th May 2019, 3:39 AM
Abdul S Ansari
Abdul S Ansari - avatar
+ 1
Diego still not working 🙁 Now I'm gonna restart making it.
24th May 2019, 3:54 AM
Abdul S Ansari
Abdul S Ansari - avatar