Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 1] guessing game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from random import randint

def tips():
player1 = randint(1, 100)
while True:
try:
player2 = int(input("Hádej číslo: "))
if player1 > player2:
print("Příliš malé")
continue
elif player2 > player1:
print("Příliš velké")
continue
else:
print("Vyhráváš")
break
except:
print("Toto není číslo!")

tips()
62 changes: 62 additions & 0 deletions 2] loto/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from random import shuffle

def lotto_user():
"""Funkce pro čísla uživatele, které si zadá na klávesnici"""

print("Zadej unikátní čísla v rozsahu 1 - 49")

try:
numbers = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lepsi je set, protoze delas membership test pres in operator

for x in range(6):
number = int(input("Zadej číslo:"))
if 0 < number <= 49 and number not in numbers:

numbers.append(number)
else:
print("Číslo není v rozsahu nebo není unikátní")
return None
numbers.sort()
return numbers

except ValueError:
print("Toto není číslo!")
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takhle ne. Tahle logika je chybna. Ty obalujes v try cely ten loop a to neni ok, protoze kdyz kupr. hned v prvni iteraci zada cislo 99 tak to vyskoci s None a ty v tom listu nic nemas. Toto neni spravne reseni. Tim try nesmis obalit cely ten loop, ale musis ten try/except mit uvnitr toho loopu



def lotto_pc():
"""Funkce pro vylosování čísel Lotta"""
numbers = list(range(1, 49))
shuffle(numbers)
lotto = numbers[:6]
lotto.sort()

return lotto


def lotto_hit(x, y):
"""Funkce pro porovnání listů"""
intersection_set = set(x) & set(y)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to je presne ono - ty vytvoris listy a pak je tady predelavas na sety. To je lepsi aby ty funkce uz hned vytvorily ty sety a nemueslo se to dit tady


if intersection_set:

print("Seznamy mají společné hodnoty:", intersection_set)
print("Počet společných hodnot:", len(intersection_set))
else:
print("Seznamy nemají žádné společné hodnoty.")


def lotto():
"""Hlavní funkce Lotta, která volá ostatní"""
x = lotto_user()
if x is None:
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto tady nema byt, tobe nemuze takova podminka nasat pokud mas tu logiku spravne, user musi vybrat 6 cisel

y = lotto_pc()
print("Toto jsou tvoje čísla:")
print(" ,".join(map(str, x)))
print("Toto jsou vylosovaná čísla:")
print(" ,".join(map(str, y)))
return lotto_hit(x, y)

lotto()


39 changes: 39 additions & 0 deletions 3] guessing game 2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
print("Mysli na číslo v rozmezí 1 - 1000 a já se pokusím jej uhodnout.")

#ověření švindlíře
my_number = int(input("Sem zadej své číslo: "))

#výchozí hodnoty
min = 0
max = 1000

#zacyklení hádání
x = 0

while x < 10:
Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tohle je pomerne komplikovane reseni. Ty tady vubec nemas pracovat s 10 pokusy jako s kontrolni promenou v tom loopu. To, ze ten pocitace to uhadne maximalne do 10 pokusu je dano tim, ze kdyz je ten algoritmus spravne napsany, tak bezi v logaritmicke komplexite a log(1000) je 10. S tim ale ty vubec nemas pracovat, to se deje proste automaticky.

ta podminka na while ma vypadat trochu jinak, zkus se jeste zamyslet.


guess = int((max - min) // 2 + min)
print(f"Je to číslo {guess}?")
x += 1

#dotaz na hodnotu
answer = input("Zadej moc, málo nebo vyhráls: ")
dictionary = {'moc':max, 'málo':min, 'vyhráls':True}
allowed_answers = list(dictionary.keys())

#pomínky pro správný proces
if x == 10:
print("Jsi švindlíř!!!")

if answer in allowed_answers:
if answer == 'moc':
max = guess
elif answer == 'málo':
min = guess
elif guess == my_number:
print("Vyhrál jsi :D")
break

else:
print(f"Neplatná odpověď zadej {', '.join(allowed_answers)}")
x -= 1
42 changes: 42 additions & 0 deletions 4] guessing game 3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)

@app.route('/')
def index():
return render_template('welcome.html')

min = 0
max = 1000
guess = (max - min) // 2 + min

@app.route('/index', methods=['GET', 'POST'])
def game():

global min, max, guess

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

globalni promenne se moc pouzivat neuc, to je bad practise a pouzije se to jen kdyz musis neco hodne ohybat a hacknout. To tady neni potreba


print(guess)
print(min, max)

if request.method == 'POST':
# Získání hodnot z formuláře
action = request.form['action']
# Aktualizace rozsahu podle odpovědi uživatele
if action == 'Příliš malé':
min = guess
elif action == 'Příliš velké':
min = guess
elif action == 'Vyhráváte':
return win()
# Výpočet nového odhadu
guess = (max - min) // 2 + min

# Renderování šablony s aktuálními hodnotami pro hru
return render_template('index.html', guess=guess, min=min, max=max)

@app.route('/win')
def win():
return render_template('win.html', guess=guess) # Zobrazení stránky pro vítězství

if __name__ == '__main__':
app.run(debug=True)
19 changes: 19 additions & 0 deletions 4] guessing game 3/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="cz">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game</title>
</head>
<body>
<h1>Hra s čísly</h1>
<form method="POST">
<p>Je číslo <b>{{ guess }}</b> příliš malé, příliš velké nebo výherní?</p>
<input type="hidden" name="min" value="{{ min }}">
<input type="hidden" name="max" value="{{ max }}">
<button type="submit" name="action" value="Příliš malé">Příliš malé</button>
<button type="submit" name="action" value="Příliš velké">Příliš velké</button>
<button type="submit" name="action" value="Vyhráváte">Vyhrál jsi!</button>
</form>
</body>
</html>
15 changes: 15 additions & 0 deletions 4] guessing game 3/templates/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="cz">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Mylsi na číslo v rozsahu 0 - 1000</h1>
<p>Jsi připraven? Klikni na tlačítko:</p>
<form action="/index" method="GET">
<button type="submit">Začít hru</button>
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions 4] guessing game 3/templates/win.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="cz">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Win</title>
</head>
<body>
<h1>Gratuluji, vyhrál jsi s číslem {{guess}}!</h1>
<p>Děkuji za hru!</p>
</body>
</html>
1 change: 1 addition & 0 deletions 5] 2001/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

36 changes: 36 additions & 0 deletions 5] dice/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import re
from random import randint

def roll(kostky):
Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ufff.. no jako.. celkem komplikovane zase. V pythonu jde casto o citelnost a nejakou primocarost toho kodu, tohle da pomerne znacnou namahu to precist a vyznat se co je co...

Rozhodne to jde zjednodusit, kdyztak se podivej jak, ja jsem nejak posilal svoji vetev.

Ale ze je videt zes to asi delala sama a nejak o tom premyslela.

Good Job


#zde jsou pomocné proměnné pro parsovani
x = re.findall("(\d+)D", kostky)
if not x:
x = "1"
y = re.findall("D(\d+)", kostky)
if not any(hodnota in y for hodnota in ['3', '4', '6', '8', '10', '12', '20', '100']):
return "Neplatná hodnota"
z = re.findall("\+(\d+)", kostky)
if not z:
z = "0"
d = re.findall("\-(\d+)", kostky)
if not d:
d = "0"

#převod proměnných na čísla
pocet = int(x[0])
hrany = int(y[0])
plus = int(z[0])
minus = int(d[0])

#vypočet počtu kostek a hran
cisla = 0
for hody in range(pocet):
cislo = randint(1, hrany)
cisla += cislo
#vysledná suma i s modifikatorem
vysledek = cisla + plus - minus

return vysledek

print(roll("5D10+20"))