Commit 47d75288 authored by cermak's avatar cermak
Browse files

Lesson 8 solution

parent 528a33c1
Pipeline #21413 passed with stage
in 1 minute and 38 seconds
def mujrange(n):
i = 0
while i < n:
yield i
i += 1
def kartezsky_soucin(l1, l2):
for x in l1:
for y in l2:
yield (x, y)
from collections import defaultdict
def kgramy(text, k):
stat=defaultdict(int)
for i in range(len(text)-k+1):
stat[text[i:i+k]] += 1
return stat
\ No newline at end of file
......@@ -3,32 +3,27 @@
x, y = 0, 0
dx, dy = 1, 0
def prikaz_krok():
global x, y, dx, dy
def fKROK():
global x,y,dx,dy
x += dx
y += dy
def prikaz_vlevo():
def fVLEVO():
global dx, dy
dx, dy = -dy, dx
def prikaz_vpravo():
global dx, dy
dx, dy = dy, -dx
prikazy = {
"krok": prikaz_krok,
"vlevo": prikaz_vlevo,
"vpravo": prikaz_vpravo,
commands = {
"KROK": fKROK,
"VLEVO": fVLEVO
}
def proved(prikaz):
if prikaz in prikazy:
prikazy[prikaz]()
else:
print("Neznámý příkaz!")
while True:
print(f"Pozice: ({x},{y}), směr: ({dx},{dy})")
prikaz = input("Příkaz: ")
proved(prikaz)
prikaz = input("Zadej příkaz:")
if not prikaz:
break
if prikaz in commands:
commands[prikaz]()
else:
print("Nerozumím")
print(f"Karel je na {x=} a {y=}, kouká se směrem ({dx},{dy})")
print("KONEC")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment