https://naucse.python.cz/2023/praha-pyladies-podzim/sessions/while-functions/
Last active
October 4, 2023 14:57
-
-
Save brabemi/b1685fb11c9305a794d8fa867bdf45e3 to your computer and use it in GitHub Desktop.
PyLadies - Praha - podzim 2023 - Lekce 4 – While & Opakování cyklů (3. 10. 2023)
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
""" | |
Napiš program, který postupně z jednotlivých 'X' vypíše: | |
X | |
X X | |
X X X | |
X X X X | |
""" | |
# for radek in range(4): | |
# print(radek, (radek + 1) * 'X ') | |
# for radek in range(4): | |
# pocet_x = radek + 1 | |
for radek in range(1,5): | |
pocet_x = radek | |
for pozice in range(pocet_x): | |
print('X', end=" ") | |
print() |
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
odpoved = input("Už tam budem? ") | |
# verze pomocí for | |
for dotaz in range(9999999): | |
if odpoved == "ano" or odpoved == "Ano" or odpoved == "ANO": | |
print("Hurá!!!") | |
break | |
else: | |
odpoved = input("Už tam budem? ") | |
# verze pomocí while | |
while odpoved != "ano": | |
odpoved = input("Už tam budem? ") | |
print("Hurá!!!") |
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
# Ukol 1 | |
# nahodné číslo 1-10 | |
# Program nechá uživatele hádat číslo | |
# Pokud se uživatel trefí program pogratuluje | |
# Pokud ne uživatel hádá znovu | |
import random | |
nahodne_cislo = random.randrange(10) | |
print(nahodne_cislo) | |
tip = int(input("Hádej číslo 0-9: ")) | |
while tip != nahodne_cislo: | |
tip = int(input("Hádej číslo 0-9: ")) | |
print("Hurá uhodl jsi!") |
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
import random | |
uspech = 0 | |
while True: | |
tah = random.randrange(2) | |
if tah == 0: | |
tah = "panna" | |
else: | |
tah = "orel" | |
# print(tah) | |
tip = input("Panna nebo orel nebo konec? ") | |
if tip == tah: | |
print("Trefa!") | |
# uspech = uspech + 1 | |
uspech += 1 | |
if uspech == 3: | |
break | |
elif tip == "konec": | |
break | |
else: | |
print("Těsně vedle :(") | |
print("Dosáhl jsi", uspech, "úspěchů") |
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 cislo in range(34): | |
if cislo % 2 == 0: | |
continue | |
pass | |
if cislo % 5 == 0: | |
continue | |
if cislo % 13 == 0: | |
continue | |
print(cislo) |
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
# program který hází dokud nepadne 6 | |
# vypisuje jednotlivé hody | |
# na závěr vypíše kolik bylo třeba pokusů | |
# Bonus: na závěr vypsat součet všech hodů | |
import random | |
# možno použít while True: a break | |
pocet_hodu = 0 | |
soucet_hodu = 0 | |
while True: | |
hod = random.randrange(1,7) | |
pocet_hodu += 1 | |
soucet_hodu += hod | |
print(hod) | |
if hod == 6: | |
break | |
# if hod == 6: | |
# break | |
# else: | |
# print(hod) | |
print("Bylo potřeba", pocet_hodu, "hodů") | |
print("Součet hodů je", soucet_hodu) |
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
# program který hází 3 kostkami dokud nepadne 6 na všech | |
# na závěr vypíše kolik bylo třeba pokusů | |
import random | |
# možno použít while True: a break | |
pocet_pokusu = 0 | |
while True: | |
uspech = 0 | |
for kostka in range(5): | |
hod = random.randrange(1,7) | |
if hod == 6: | |
uspech += 1 | |
pocet_pokusu += 1 | |
print("pokus", pocet_pokusu, "uslechu", uspech) | |
if uspech == 5: | |
break | |
print("Bylo potřeba", pocet_pokusu, "hodů") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment