Last active
October 1, 2020 20:44
-
-
Save brabemi/c4cfda120d6204a3847ccf58dc3b7f26 to your computer and use it in GitHub Desktop.
PyLadies - Praha - podzim 2020 - Lekce 3 – Funkce a cyklus For
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
# print("", len("")) | |
# print("1", len("1")) | |
# print("12", len("12")) | |
# print("1234", len("1234")) | |
retezec = "ahoj" | |
delka = len(retezec) | |
print(delka, delka**2) | |
print("delka řetězce", retezec, "je", len(retezec)) | |
if len('Ahoj!') <= 3: | |
print('pozdrav je krátký') | |
else: | |
print("Pozdrav je správně dlouhý") |
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
print() | |
print(1) | |
print(1, 2, 3, 4, 10) | |
print(1, 2, 3, 4, 10, sep=",") | |
print(1, 2, 3, 4, 10, sep=" + ") | |
print("Ahoj") | |
print("Hello") | |
print("Ahoj", end=" - ") | |
print("Hello") | |
print("Ahoj", "nazdar", "čau", sep=", ", end=" - ") | |
print("Hello", "hi", sep=", ") | |
# vytisknou čísla 1-5 dát mezi ně " + ", konec " = " | |
# v dalším printu 15 a nový řádek | |
print(1, 2, 3, 4, 5, sep=" + ", end=" = ") | |
print(15) | |
input() |
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
int_cislo = 3 | |
float_cislo = 3.5 | |
retezec_cislo = "3.500000" | |
print(float_cislo == retezec_cislo) | |
print(str(float_cislo) == retezec_cislo) | |
print(float_cislo == float(retezec_cislo)) | |
print(int(3.1), int(3.9)) |
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 math import sqrt, floor, ceil | |
print(int(3.1), int(3.9)) | |
print(round(3.1), round(3.5), round(3.9)) | |
print(sqrt(81)) | |
print(floor(3.1), floor(3.5), floor(3.9)) | |
print(ceil(3.1), ceil(3.5), ceil(3.9)) |
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 randrange | |
# print(randrange(1, 7)) | |
# cislo = randrange(1, 4) | |
# if cislo == 1: | |
# print("pes") | |
# elif cislo == 2: | |
# print("kočka") | |
# elif cislo == 3: | |
# print("papoušek") | |
# else: | |
# print("Tohle zvíře neznám") | |
# použij randrange a do proměnné | |
# tah náhodně ulož kámen, nůžky nebo papír | |
tah = "nedefinováno" | |
cislo = randrange(1, 4) # -> 1, 2 nebo 3 | |
if cislo == 1: | |
tah = "kámen" | |
elif cislo == 2: | |
tah = "nůžky" | |
elif cislo == 3: | |
tah = "papír" | |
print(tah) |
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 turtle import forward, left, right, exitonclick, shape | |
strana = 150 | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
left(20) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
left(20) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
left(20) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
left(20) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
forward(strana) | |
left(90) | |
left(20) | |
exitonclick() |
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
for pokus in 1, 2, 3, 4, 5, 7: | |
print(pokus) | |
print("-"*80) | |
for pokus in range(7): | |
print(pokus) | |
print("-"*80) | |
for pokus in range(1, 8): | |
print(pokus) | |
print("-"*80) | |
maximum = int(input("Zadej maximum")) | |
soucet = 0 | |
for cislo in range(1, maximum + 1): | |
soucet = soucet + cislo | |
print(cislo, soucet) | |
print("součet je", soucet) |
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 turtle import forward, left, right, exitonclick, shape | |
strana = 150 | |
pocet_ctvercu = 10 | |
for cislo_ctverce in range(pocet_ctvercu): | |
# jeden čtverec | |
for krok in range(4): | |
forward(strana) | |
left(90) | |
# otočení o 20° | |
left(20) | |
exitonclick() |
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 turtle import forward, left, right, exitonclick, shape | |
# nakreslit schody strana = 100 | |
# pocet_schodu = 5 | |
# použít for cyklus | |
strana = 50 | |
pocet_schodu = 15 | |
for schod in range(pocet_schodu): | |
print(schod) | |
# jeden schod | |
forward(strana) | |
left(90) | |
forward(strana) | |
right(90) | |
exitonclick() |
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 turtle import forward, left, right, exitonclick, shape | |
for sestiuhelnik in range(6): | |
# sestiuhelnik | |
for strana in range(6): | |
forward(50) | |
left(60) | |
forward(50) | |
right(60) | |
exitonclick() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment