I want to be able to play sudoku in a 2d format.
Drop files here
or click to upload
import streamlit as st
import numpy as np
# Initialize the board
if 'sudoku_board' not in st.session_state:
st.session_state.sudoku_board = np.zeros((9, 9), dtype=int)
st.title('Sudoku Game')
# Function to display the Sudoku board
def display_board(board):
for i in range(9):
cols = []
for j in range(9):
if board[i, j] != 0:
cols.append(st.number_input(f'[{i},{j}]', min_value=1, max_value=9, value=board[i, j], key=f'cell_{i}_{j}'))
else:
cols.append(st.number_input(f'[{i},{j}]', min_value=0, max_value=9, value=0, key=f'cell_{i}_{j}'))
st.write(cols)
# Update the board based on user inputs
for i in range(9):
for j in range(9):
st.session_state.sudoku_board[i, j] = st.session_state.get(f'cell_{i}_{j}', 0)
# Display the board
display_board(st.session_state.sudoku_board)
# Button to reset the board
if st.button('Reset Board'):
st.session_state.sudoku_board = np.zeros((9, 9), dtype=int)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?