Created
August 31, 2015 23:05
-
-
Save marcoscastro/b91b2899b13697ead6dd to your computer and use it in GitHub Desktop.
Python - Gerando arquivo HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # encoding:utf-8 | |
| # string com o código HTML | |
| codigo_html = ''' | |
| <html> | |
| <head> | |
| <title>www.GeeksBR.com</title> | |
| <script src="script.js"></script> | |
| </head> | |
| <body> | |
| <center> | |
| <h1><a href="http://www.geeksbr.com">www.GeeksBR.com</a></h1> | |
| <h3>Aprendendo Python no GeeksBR...</h3> | |
| <div id="div1"> | |
| <textarea id="textarea1" rows="4" cols="50">Digite algo aqui...</textarea><br/><br/> | |
| <button onclick="mostrar_conteudo()">Executar</button> | |
| </div> | |
| </center> | |
| </body> | |
| </html> | |
| ''' | |
| # string com o código JavaScript | |
| codigo_javascript = ''' | |
| function mostrar_conteudo() { | |
| var elem = document.getElementById("textarea1"); | |
| var texto = elem.value; | |
| alert("O texto digitado possui " + texto.length + " caracteres."); | |
| } | |
| ''' | |
| # abre o arquivo HTML para escrita | |
| arq_html = open('index.html', 'w') | |
| # abre o arquivo JavaScript para escrita | |
| arq_js = open('script.js', 'w') | |
| # escrevendo no arquivo HTML | |
| arq_html.write(codigo_html) | |
| # escrevendo no arquivo JavaScript | |
| arq_js.write(codigo_javascript) | |
| # fechando os arquivos | |
| arq_html.close() | |
| arq_js.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import socket
def print_board(board):
print(" | |")
print(" {} | {} | {}".format(board[0], board[1], board[2]))
print("||")
print(" | |")
print(" {} | {} | {}".format(board[3], board[4], board[5]))
print("||")
print(" | |")
print(" {} | {} | {}".format(board[6], board[7], board[8]))
print(" | |")
def check_win(board):
win_combinations = [(0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6)]
for combo in win_combinations:
if board[combo[0]] == board[combo[1]] == board[combo[2]] != ' ':
return True
return False
def check_tie(board):
return all(x != ' ' for x in board)
def main():
# Configurando o servidor
host = '127.0.0.1'
port = 5555