-
Notifications
You must be signed in to change notification settings - Fork 16
Workshop_denisa #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Workshop_denisa #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| 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 = [] | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
||
|
|
||
| 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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| 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> |
| 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> |
| 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import re | ||
| from random import randint | ||
|
|
||
| def roll(kostky): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")) | ||
There was a problem hiding this comment.
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