Created
April 11, 2019 17:59
-
-
Save messa/8ca5cad3bee039d7c0f2dd8d6d3a1aeb to your computer and use it in GitHub Desktop.
Pyladies opakovani 2019-04-11
This file contains 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
def ruzne_ctverce(): | |
for delka_strany in 2, 5, 7: | |
ctverec(delka_strany, symbol='O') | |
def ctverec(n, symbol='X'): | |
for cislo_radku in range(n): | |
for cislo_sloupce in range(n): | |
if ( | |
cislo_radku == 0 or | |
cislo_sloupce == 0 or | |
cislo_sloupce == n-1 or | |
cislo_radku == n-1 | |
): | |
policko = symbol | |
else: | |
policko = ' ' | |
print(policko, end=' ') | |
print() | |
ruzne_ctverce() |
This file contains 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
from random import randint, randrange | |
def tah_pocitace(pole): | |
"Vrátí herní pole se zaznamenaným tahem počítače" | |
while True: | |
# Vyber číslo od 0 do 19. | |
#n = randrange(0, 20) | |
n = randint(0, 19) | |
# Pokud je dané políčko volné, hrej na něj. | |
if pole[n] == '-': | |
# pole = pole[:n] + 'X' + pole[n+1:] | |
pole = tah(pole, n, 'X') | |
return pole | |
def tah(pole, cislo_policka, symbol): | |
"Vrátí herní pole s daným symbolem umístěným na danou pozici" | |
pole = pole[:cislo_policka] + symbol + pole[cislo_policka+1:] | |
return pole | |
print(tah_pocitace(17 * 'O' + '---')) | |
def piskvorky1d(): | |
''' | |
Vytvoří řetězec s herním polem a střídavě volá funkce | |
tah_hrace a tah_pocitace, dokud někdo nevyhraje nebo | |
nedojde k remíze. | |
''' | |
herni_pole = 20 * '-' | |
while True: | |
pole = tah_hrace(pole) | |
print(pole) | |
# TODO: kontrola, zda neni konec hry | |
pole = tah_pocitace(pole) | |
print(pole) | |
# TODO: kontrola, zda neni konec hry | |
def piskvorky1d(): | |
''' | |
Vytvoří řetězec s herním polem a střídavě volá funkce | |
tah_hrace a tah_pocitace, dokud někdo nevyhraje nebo | |
nedojde k remíze. | |
''' | |
herni_pole = 20 * '-' | |
kdo_je_na_tahu = 'hrac' | |
while True: | |
if kdo_je_na_tahu == 'hrac': | |
pole = tah_hrace(pole) | |
kdo_je_na_tahu = 'pocitac' | |
else: | |
pole = tah_pocitace(pole) | |
kdo_je_na_tahu == 'hrac' | |
print(pole) | |
# TODO: kontrola, zda neni konec hry |
This file contains 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
#f = open('basnicka.txt', encoding='utf-8') | |
#print(f.read()) | |
#f.close() | |
# with open('basnicka.txt', encoding='utf-8') as f: | |
# n = 0 | |
# while True: | |
# n += 1 | |
# radek = f.readline() | |
# if not radek: | |
# break | |
# print('radek', n, ':', radek) | |
# | |
# print('---------') | |
#with open('kopie.txt', encoding='utf-8', mode='w') as kopie: | |
with open('kopie.txt', encoding='utf-8', mode='a') as kopie: | |
#with open('basnicka.txt', encoding='utf-8', mode='r') as f: | |
with open('basnicka.txt', encoding='utf-8') as f: | |
n = 0 | |
for radek in f: | |
n += 1 | |
#print('radek', n, ':', radek.upper(), file=kopie, end='') | |
print('radek', n, ':', radek.upper().rstrip(), file=kopie) | |
#vystup.write('radek ' + str(n) + ' : ' + radek.upper()) | |
''' | |
Chyba "io.UnsupportedOperation: not writable" -> chybi mode='w' | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment