https://naucse.python.cz/2021/pyladies-praha-podzim2021/sessions/while-functions/
Last active
November 28, 2021 22:41
-
-
Save brabemi/663c22d067873873273a67d0468b1209 to your computer and use it in GitHub Desktop.
PyLadies - Praha - podzim 2021 - Lekce 4 – While & Opakování cyklů
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
radku = 5 | |
sloupcu = 5 | |
for radek in range(radku): | |
for sloupec in range(sloupcu): | |
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
# for dotaz in range(100000): | |
# odpoved = input('Už tam budem? ') | |
# if odpoved == 'ano': | |
# print('Huráááááá') | |
# break | |
# odpoved = input('Už tam budem? ') | |
# while odpoved != 'ano' and odpoved != 'ANO': | |
# print('Ale já už mám hlad!') | |
# odpoved = input('Už tam budem? ') | |
# print('Huráááá') | |
while True: | |
odpoved = input('Už tam budem? ') | |
if odpoved == 'ano' or odpoved == 'ANO': | |
break | |
elif odpoved == 'a' or odpoved == 'A': | |
break | |
# from random import randrange | |
# while True: | |
# cislo = randrange(10000) | |
# print('Číslo je', cislo) | |
# print('(Počkej, než se počítač unaví...)') | |
# if cislo > 5000: | |
# break |
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 | |
tahu = 0 | |
skore = 0 | |
# while True: | |
# tip = input('Panna nebo orel? ') | |
# if tip == 'panna' or tip == 'orel': | |
# hod = randrange(2) | |
# if hod == 0: | |
# strana = 'panna' | |
# else: | |
# strana = 'orel' | |
# if tip == strana: | |
# print('Super trefil jsi se') | |
# skore = skore + 1 | |
# else: | |
# print('Těsně vedle') | |
# tahu = tahu + 1 | |
# print(skore, 'z', tahu) | |
# else: | |
# print('Napiš panna nebo orel') | |
while True: | |
tip = input('Panna nebo orel? ') | |
# if tip != 'panna' and tip != 'orel': | |
if not(tip == 'panna' or tip == 'orel') : | |
print('Zadej panna nebo orel') | |
continue | |
hod = randrange(2) | |
if hod == 0: | |
strana = 'panna' | |
else: | |
strana = 'orel' | |
if tip == strana: | |
print('Super trefil jsi se') | |
skore = skore + 1 | |
else: | |
print('Těsně vedle') | |
tahu = tahu + 1 | |
print(skore, 'z', tahu) |
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ů | |
from random import randrange | |
suma = 0 | |
pokus = 0 | |
while True: | |
hod_kostkou = randrange(6) + 1 | |
# pokus = pokus + 1 | |
pokus += 1 | |
suma += hod_kostkou | |
print(pokus, '. pokus, padlo ', hod_kostkou, sep='') | |
if hod_kostkou == 6: | |
break | |
print('Pro hození 6 bylo potřeba', pokus, 'pokusů') | |
print('Suma všech hodů je', suma, 'a průměr', suma/pokus) |
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 i in range(20): # Vnější cyklus | |
# if i%2 == 1: | |
# for j in range(20): # Vnitřní cyklus | |
# print(j * i, end=' ') | |
# if i <= j: | |
# break | |
# print() | |
# for i in range(20): # Vnější cyklus | |
# if i%2 == 0: | |
# continue | |
# for j in range(20): # Vnitřní cyklus | |
# print(j * i, end=' ') | |
# if i <= j: | |
# break | |
# print() | |
for i in range(19,0,-2): # Vnější cyklus | |
print(i) | |
for j in range(20): # Vnitřní cyklus | |
print(j * i, end=' ') | |
if i <= j: | |
break | |
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
# házej 3 D6 kostkami naráz dokud nepadne 6 na všech najednou | |
from random import randrange | |
pocet_kostek = 7 | |
pocet_sten = 8 | |
kolo = 0 | |
while True: | |
soucet_hodu = 0 | |
kolo += 1 | |
print('Kolo č.', kolo, 'padlo', end=' ') | |
for kostka in range(pocet_kostek): | |
hod_kostkou = randrange(1,pocet_sten+1) | |
soucet_hodu += hod_kostkou | |
print(hod_kostkou, end=' ') | |
print() | |
# print('Kolo č.', kolo, 'padlo', hod_kostkou_1, hod_kostkou_2, hod_kostkou_3) | |
if soucet_hodu == pocet_kostek * pocet_sten: | |
break |
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
# máme 4 figurky, musíme hodit 6 abychom opustli domeček | |
# napište program, který bude 4x házet tak dlouho dokud nepadne 6 | |
# Kolíkrát bylo potřeba hodit | |
from random import randrange | |
# pocet_hodu = 0 | |
# for figurka in range(4): | |
# while True: | |
# hod_kostkou = randrange(1,7) | |
# pocet_hodu += 1 | |
# if hod_kostkou == 6: | |
# break | |
# print('Pro figurku č.', figurka + 1, 'padla 6 v hodu č.', pocet_hodu) | |
pocet_hodu = 0 | |
pocet_6 = 0 | |
while pocet_6 < 4: | |
hod_kostkou = randrange(1,7) | |
pocet_hodu += 1 | |
if hod_kostkou == 6: | |
pocet_6 += 1 | |
print('Pro figurku č.', pocet_6, 'padla 6 v hodu č.', pocet_hodu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment