Hi everyone,
Im working on a a sudoku program for python and i need some help. The program will ask input from the user for 9 rows of numbers that hopefully contain the digits 1-9. Once they input all 9 rows the program should then go through each row and verify and see if it satisfies the conditions of a sudoku game. If it doesnt it will return a error message and display which row has an error. Now what i need help in is how to best check the rows without writing 9 different if statements. I need to incorporate a loop. How would i do this?
My progress in code so far is below:
from a5_import import *
import sys
sep = "-.-.-.-.-.-.-.-.-.-.-.-.-.-.-."
print sep
print " Sudoku Verifier! "
print sep
row_0=int(raw_input("Enter Row 0: "))
row_1=int(raw_input("Enter Row 1: "))
row_2=int(raw_input("Enter Row 2: "))
row_3=int(raw_input("Enter Row 3: "))
row_4=int(raw_input("Enter Row 4: "))
row_5=int(raw_input("Enter Row 5: "))
row_6=int(raw_input("Enter Row 6: "))
row_7=int(raw_input("Enter Row 7: "))
row_8=int(raw_input("Enter Row 8: "))
if not check9(row0):
print "Error: row 0 is invalid."
if not check9(row1):
print "Error: row 1 is invalid."
if not check9(row2):
print "Error: row 2 is invalid."
if not check9(row3):
print "Error: row 3 is invalid."
if not check9(row4):
print "Error: row 4 is invalid."
if not check9(row5):
print "Error: row 5 is invalid."
if not check9(row6):
print "Error: row 6 is invalid."
if not check9(row7):
print "Error: row 7 is invalid."
if not check9(row8):
print "Error: row 8 is invalid."
print sep
Again the requirements are i need the following three things to be accomplished:
- The program produces the correct output
- The program uses a loop correctly to check the columns of the input.
- The program uses a loop correctly to check the boxes of the input.
Thanks for your help with the verifier loops.