A game of sudoku that I want to play inside streamlit
Drop files here
or click to upload
import streamlit as st
import numpy as np
def create_sudoku_grid():
# Create an empty 9x9 Sudoku grid
grid = np.zeros((9, 9), dtype=int)
return grid
def is_valid_move(grid, row, col, num):
# Check if num is not in the given row and column
if num in grid[row] or num in grid[:, col]:
return False
# Check the 3x3 sub-grid
start_row, start_col = 3 * (row // 3), 3 * (col // 3)
if num in grid[start_row:start_row + 3, start_col:start_col + 3]:
return False
return True
def draw_grid(grid):
for i in range(9):
for j in range(9):
st.text_input('', value=str(grid[i][j]) if grid[i][j] != 0 else '', key=f'{i}-{j}')
st.title('Sudoku Game')
sudoku_grid = create_sudoku_grid() # Initialize a Sudoku grid
st.subheader('Fill the Sudoku grid:')
draw_grid(sudoku_grid)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?