diff --git a/1] guessing game/main.py b/1] guessing game/main.py index e69de29..d0aa099 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -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() \ No newline at end of file diff --git a/2] loto/main.py b/2] loto/main.py index e69de29..2584265 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -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 = [] + 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 + + +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) + + 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 + 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() + + diff --git a/3] guessing game 2/main.py b/3] guessing game 2/main.py index e69de29..280b6e5 100644 --- a/3] guessing game 2/main.py +++ b/3] guessing game 2/main.py @@ -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: + + 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 diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index e69de29..0587769 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -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 + + 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) \ No newline at end of file diff --git a/4] guessing game 3/templates/index.html b/4] guessing game 3/templates/index.html new file mode 100644 index 0000000..6fd6d0d --- /dev/null +++ b/4] guessing game 3/templates/index.html @@ -0,0 +1,19 @@ + + + + + + Game + + +

Hra s čísly

+
+

Je číslo {{ guess }} příliš malé, příliš velké nebo výherní?

+ + + + + +
+ + \ No newline at end of file diff --git a/4] guessing game 3/templates/welcome.html b/4] guessing game 3/templates/welcome.html new file mode 100644 index 0000000..9f396de --- /dev/null +++ b/4] guessing game 3/templates/welcome.html @@ -0,0 +1,15 @@ + + + + + + Welcome + + +

Mylsi na číslo v rozsahu 0 - 1000

+

Jsi připraven? Klikni na tlačítko:

+
+ +
+ + \ No newline at end of file diff --git a/4] guessing game 3/templates/win.html b/4] guessing game 3/templates/win.html new file mode 100644 index 0000000..9548a53 --- /dev/null +++ b/4] guessing game 3/templates/win.html @@ -0,0 +1,12 @@ + + + + + + Win + + +

Gratuluji, vyhrál jsi s číslem {{guess}}!

+

Děkuji za hru!

+ + \ No newline at end of file diff --git a/5] 2001/main.py b/5] 2001/main.py index e69de29..8b13789 100644 --- a/5] 2001/main.py +++ b/5] 2001/main.py @@ -0,0 +1 @@ + diff --git a/5] dice/main.py b/5] dice/main.py index e69de29..e8ef56c 100644 --- a/5] dice/main.py +++ b/5] dice/main.py @@ -0,0 +1,36 @@ +import re +from random import randint + +def roll(kostky): + + #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")) \ No newline at end of file