Created
September 24, 2020 20:11
-
-
Save brabemi/13f160d362fc2c66d196ebe44a16ce98 to your computer and use it in GitHub Desktop.
PyLadies - Praha - podzim 2020 - Lekce 2 – Proměnné a podmínky
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("") # prázdný řetězec | |
print("Ahoj") # toto vytiskne Ahoj | |
print(1) | |
print(0.1) | |
print(1, 2, 3, 4) | |
print("ahoj", 1, 0.1, "konec") | |
print(3*4) | |
print("ahoj" + " to je vše") | |
print("ahoj" * 80) | |
print("Ahoj" * 80) | |
print(8/0.1) | |
print("ahoj") |
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
ahoj = "Ahoj!" # takhle nadefinu proměnnou | |
print(ahoj) | |
print(ahoj*2) | |
ahoj = 1 # Obsah proměnné lze zmenit | |
print(ahoj*ahoj) | |
print("V ahoj má být", ahoj + 1) | |
ahoj = ahoj + 1 # A dokonce lze aktualizovat pomocí "sebe sama" | |
print(ahoj) |
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
vstup = input("Zadej délku strany: ") | |
# strana = int(vstup) # int = celé číslo | |
strana = float(vstup) # float = desetinné číslo | |
# strana = float(input("Zadej délku strany: ")) # lze zapsat i na jeden řádek | |
delka_je_kladna = strana > 0 | |
# if strana > 0: | |
if delka_je_kladna: | |
obvod = 4 * strana | |
obsah = strana**2 | |
print("Nasledující hodnoty jsou správně", delka_je_kladna) | |
# obvod čtverce je 4 * strana | |
print("Obvod čtverce se stranou", strana, "cm je", obvod, "cm") | |
# obsah čtverce je strana * strana nebo strana**2 | |
print("Obsah čtverce se stranou", strana, "cm je", obsah, "cm2") | |
print("Obsah / obvod je", obsah / obvod) | |
else: | |
print("Zadejte kladné číslo") |
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(1 == 1) | |
print(1 == 2) | |
print(1 != 1) | |
print(1 != 2) | |
print(1 > 2) | |
print(1 < 2) | |
print(1 > 1) | |
print(1 >= 1) | |
print(2 < 3 and 5 < 3) | |
print(2 < 3 and 5 < 8) | |
print(6 < 3 or 5 < 3) | |
print(2 < 3 or 5 < 3) | |
print(2 < 3 or 5 < 8) | |
print(not (2 < 3 or 5 < 8)) |
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
vek = int(input("Zadej vek: ")) | |
# oveřit že vek > 0 | |
# nabídnout sunar pro mladší 3 let | |
if vek <= 0: | |
print("zadej kladný věk") | |
elif vek < 3: | |
print("Dáš si sunar") | |
elif vek < 15: | |
print("Dáš si vodu") | |
elif vek < 18: | |
limo = input("Dáš si colu nebo fantu? ") | |
# if limo == "colu" or "Colu": -> tohle je špatně znamená to if (limo == "colu") or ("Colu" != ""): | |
if limo == "colu" or limo == "Colu": | |
print("Tady máš coca colu") | |
# alternati k or | |
# if limo == "colu": | |
# print("Tady máš coca colu") | |
# elif limo == "Colu": | |
# print("Tady máš coca colu") | |
elif limo == "fantu": | |
print("Tady máš fantu") | |
else: | |
print(limo, "ti nemohu prodat") | |
else: | |
# dotaz na 10, 12 nebo nealko | |
pivo = input("Máme 10, 12 nebo nealko ") | |
# v if/elif/else může být další if | |
if pivo == "10": | |
print("Tady je jedno z Unětic") | |
elif pivo == "12": | |
print("Tady máš plzeň") | |
elif pivo == "nealko": | |
print("Tady je birel") | |
else: | |
print(pivo, "bohužel nemáme") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment