Commit a71d9073 authored by Mareš Martin's avatar Mareš Martin
Browse files

Slovníky: Příklady

parent 68ad052a
# Seznam kontaktů
kontakty = [
{
"jmeno": "Pokusný",
"prijmeni": "Králík",
"telefony": [ "123456789", "+420999888777" ],
"adresa": {
"ulice": "Norní",
"dum": "42/1b",
"mesto": "Králíky",
"psc": "987 65",
},
},
{
"jmeno": "Kocour",
"prijmeni": "Mikeš",
"telefony": [],
"adresa": {
"ulice": "Josefa Lady",
"dum": "1",
"mesto": "Hrusice",
"psc": "251 66",
}
},
]
#!/usr/bin/env python3
x, y = 0, 0
dx, dy = 1, 0
def prikaz_krok():
global x, y, dx, dy
x += dx
y += dy
def prikaz_vlevo():
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,
}
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)
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