?? ? ? ?? Python? ?? ?? ???? ????? ?? ? ????????. ??? Python? ???? ? ??? ???? ? ????? ?????. Pyscript? ??? ???? ?? ??? ????. HTML ? Python ?? ? ???? ? ?????? ?? Python ??? ??? ??? ??? ??? ?????. ?? ??? ???? Pyscript? ???? JavaScript? ??? ??? ? ?? ???? ?? ?? ?????. ? ??????? Pyscript, ??? ????, ?? ?? ? ? ?? ???? ?? Python ?? ???? ???? ??? ?? ????. ??- pyscript ? ??????
- WebApp? pyscript? ???? ??? ??????
- pyscript? ?? ??
- 1 ?? : main.py ????
- 2 ?? : CSS ??? ????
- 3 ?? : Index.html ????
- 4 ?? : pyscript.toml ????
- ??
pyscript ? ?????? Pyscript? ???? ? ??? ??? ???? ?? ?? ??? ?????. ? ?????? ?? Python ??? ??? ? ????. ??? ??? ???? ????? ??? ???? ???? ??? ??? ?? ????? ??? ? ????. Pyscript? JavaScript ?? Python??? ? ?? ???? ?? ????. ????? ??? ?? ? ? ??, ?? ?? ?? ?? ? ? ????. pyscript? ?? ??- ????? ??? : ??? ??? ??? ? ? ???? HTML ??? ?? ?? ?? ?? : ?? ????? ? ??? ??? ??? ????. ?????? ?????. HTML?? ?? ?? : Python? HTML, CSS ? JavaScript? ?? ?????. WebAssembly? ?? : Pyodide? ????? ?????? Python? ???? ?? (WebAssembly? ??? ?). WebApp? pyscript? ???? ??? ??????
1 ?? : ?? ? ???? ?????? ?? ? ???? ??????. ??? ??? ??, ???? ???? ?? ?? ? ??? ????. 

2 ?? : ?? HTML ??? ????? pyscript? ????? ??? ??? ????? ??? HTML ??? ?????. ?? ?? :
?? ? ?? pyscript ?
pyscript?? hello!
?? = "pyscript"
print (f "hello, {name}! ??? ?????? Python? ???? ????.")
3 ?? : a?? html ??? ?? ? ????.
????? 3 ?? ??? ????
main.py : Python ??.
index.html : ?? ? ???? ?? ? ?? ? ??? pyscript.
pyscript.toml : ?? Python ???? ??? ??????. ??.
??? ??? ?? ??? ?????? ??? ??????.
??? pyscript ???? pyscript playground? ???? ?????? ?? ? ??? ?? ??? ? ? ????.
pyscript
?? pyscript ?????? ?? ??? ??? ?? ??? ???????.
??? 2 ? TIC-TAC-TOE ??? ?? ? ????.
1 ?? : Update main.py main.py ??? ?? ??, ??? ?? ?? ? UI ????? ???? Tictactoe ???? ?????. Pyweb? ???? Python? HTML? ???? ???? ??? ??? ??? ????? ?? ????.
?? :
??? Tictactoe :
def __init __ (self) :
self.board = pydom [ "?#??"]]
self.status = pydom [ "h2#status"]]
self.console = pydom [ "????#??"] [0]
self.init_cells ()
self.init_winning_combos ()
self.new_game (...)
def set_status (??, ???) :
self.status.html = ???
def init_cells (self) :
self.cells = []
(0, 1, 2)?? i? ?? :
? = []
(0, 1, 2)? J? ?? :
cell = pydom [f "div#cell {i} {j}"] [0]
??? ?????
row.append (?)
self.cells.append (?)
def init_winning_combos (self) :
self.winning_combos = []
# ?? ?
(0, 1, 2)?? i? ?? :
?? = []
(0, 1, 2)? J? ?? :
combo.append ((i, j))
self.winning_combos.append (??)
# ?? ?
(0, 1, 2)? J? ?? :
?? = []
(0, 1, 2)?? i? ?? :
combo.append ((i, j))
self.winning_combos.append (??)
# ????? ?????
self.winning_combos.append ([(0, 0), (1, 1), (2, 2)]))))
self.winning_combos.append ([(0, 2), (1, 1), (2, 0)]))))
def new_game (self, event) :
self.clear_terminal ()
print ( '==================')
?? ( '??? ?? ??')
??()
(0, 1, 2)?? i? ?? :
(0, 1, 2)? J? ?? :
self.set_cell (i, j, "")
self.current_player = "x"
Experimentingself.set_status (f '{self.current_player} ?? ...')
def next_turn (self) :
Winner = self.check_winner ()
Winner == "Tie"? ?? :
self.set_status ( "??????!")
self.current_player = "" # IE, ??? ?????
??
Elif ???? ????.
self.set_status (f '{winner} wins')
self.current_player = "" # IE, ??? ?????
??
if self.current_player == "x":
self.current_player = "O"
? ??:
self.current_player = "x"
self.set_status (f '{self.current_player} ?? ...')
def check_winner (self) :
"" "
??? ????? ??????.
"x", "o", "tie"?? ??? ??????. ??? ??? ??? ???? ??? ?????.
"" "
# ??? ??? ??????
self.winning_combos? ?? :
Winner = self.get_winner (??)
??? :
# ?? ?? ??????
???? i, j? ?? :
self.cells [i] [J] .add_class ( "Win")
?? ??
# ????? ??????
(0, 1, 2)?? i? ?? :
(0, 1, 2)? J? ?? :
if self.get_cell (i, j) == "":
# ??? ? ?? ?? ???? ????.
?? ?? # ??? ??? ???????
"???"??
def get_winner (??, ??) :
"" "
??? ??? ?? ?? ??? ?? ?? ?? ??????.
??? ??? ""?????.
? ?? (i, j) ??? ?????.
?:
self.get_winner ([(0, 0), (1, 1), (2, 2)])))
"" "
Len (??) == 3? ?????
values ??= [self.get_cell (i, j)? i, ???? j]
? [0] == value [1] == value [2] ? ? [0]! = "":
?? ? [0]
?? ""
def set_cell (self, i, j, value) :
( "", "x", "o"?? ?? ?????.
cell = self.cells [i] [J]
cell.html = ?
Cell.classes?? "x"? ?? :
cell.remove_class ( "x")
Cell.classes?? "O"? ?? :
cell.remove_class ( "o")
Cell.classes?? "Win"? ?? :
cell.remove_class ( "Win")
value! = ""? ?? :
cell.add_class (?)
def get_cell (self, i, j) :
cell = self.cells [i] [J]
? = cell.html
( "", "x", "o"?? ?? ?????.
?? ?
DEF CLICK (Self, Event) :
i = int (event.target.getAttribute ( 'data-x'))
j = int (event.target.getAttribute ( 'data-y')))
print (f'cell {i}, {j} ?? : ', end =' ')
self.current_player == ""? ?? :
print ( '??? ???? ? ?? ??')
??
?
value = self.get_cell (i, j)
If value == "":
print ( '? ?, ??')
self.set_cell (i, j, self.current_player)
self.next_turn ()
? ??:
print (f'cell? ?? ?? ????.
def clear_terminal (self) :
self.console._js.terminal.clear ()
def toggle_terminal (self, event) :
hidden = self.console.parent._js.getAttribute ( "Hidden")
??? ?? :
self.console.parent._js.removeattribute ( "Hidden")
? ??:
self.console.parent._js.setattribute ( "Hidden", "Hidden")
game = tictactoe ()
2 ?? : CSS ?? ??
style.css ??? ?????? ?? Tic-Tac-Toe ??? ????? ???? ???? ?? ??. ??? ??, ? ? ?? ???? ???? ?? ????. .
?? : h1, h2 {
Font-Family : '?? ???', '?? ?', ???;
??? ?? : ??;
}
#?? {
Font-Family : '?? ???', '?? ?', ???;
?? : ??;
?? ?? : 120px;
?? : 1% ??;
??-??? : ??;
}
#board td {
?? : 4px ?? RGB (60, 60, 60);
?? : 90px;
?? : 90px;
?? ?? : ??;
??? ?? : ??;
?? : ???;
}
#board td div {
?? : 90px;
?? : 90px;
?? ?? : 90px;
????? : ??;
???? : ???;
?? : ???;
}
.x {
?? : Darksalmon;
?? : ??;
?? ?? : 1.2EM;
?? : ???;
}
.o {
?? : Aquamarine;
?? : ??;
?? ?? : 1.0EM;
?? : ???;
}
.??? {
??? : ??? ?;
}
3 ?? : ???? index.html index.html ?? ??? ?? ? ??? ??????. main.py , ?? ?? ??? ???? style.css (?? ????) ????.
?? :
? ??? pyscript : ?????? ?? ???? ?? - ?? Vidhya? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!