-
Notifications
You must be signed in to change notification settings - Fork 16
hadaci hra cislo #3
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?
Changes from all commits
04a2292
8beafc5
752a992
473eb6c
47ba2b6
960d1f2
eeb5267
cec9b91
8001c18
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,21 @@ | ||
| import random | ||
| def guess_the_number(): | ||
| secret_number = random.randint(1, 100) | ||
|
|
||
| while True: | ||
| try: | ||
| user_guess = int(input("Hádej číslo: ")) | ||
|
|
||
| if user_guess < secret_number: | ||
| print("Příliš malé!") | ||
| elif user_guess > secret_number: | ||
| print("Příliš velké!") | ||
| else: | ||
| print("Vyhráváte!") | ||
| break | ||
|
|
||
| except ValueError: | ||
| print("Není to číslo!") | ||
|
|
||
| if __name__ == "__main__": | ||
| guess_the_number() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import random | ||
|
|
||
| def hra_hadani_cisel(): | ||
| vylosovane_cislo = random.randint(1, 100) | ||
|
|
||
| while True: | ||
| tip = input("Guess the number: ") | ||
|
|
||
| if not tip.isdigit(): | ||
| print("It's not a number!") | ||
| continue | ||
|
|
||
| tip = int(tip) | ||
|
|
||
| if tip < vylosovane_cislo: | ||
| print("Too small!") | ||
| elif tip > vylosovane_cislo: | ||
| print("Too big!") | ||
| else: | ||
| print("You win!") | ||
| break | ||
|
|
||
| if __name__ == "__main__": | ||
| hra_hadani_cisel() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import random | ||
|
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. cely tenhle kod se mi zda opravdu velmi komplikovany. zkus si to rozdelit do funkci 1] to co vybere user 2] to co vybere pocitac 3] main |
||
| def zadej_cislo(): | ||
| while True: | ||
| cislo = input("Your number (1-49): ") | ||
|
|
||
| if not cislo.isdigit(): | ||
|
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. stejne jako nahore |
||
| print("It's not a number!") | ||
| continue | ||
|
|
||
| cislo = int(cislo) | ||
|
|
||
| if cislo < 1 or cislo > 49: | ||
| print("Number must be in range 1-49.") | ||
| continue | ||
|
|
||
| return cislo | ||
|
|
||
| def hra_lotto(): | ||
| vybrane_cisla = [] | ||
| for _ in range(6): | ||
| cislo = zadej_cislo() | ||
| while cislo in vybrane_cisla: | ||
|
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. uff.. tady mas dvojity loop. toto urcite neni spravna logika |
||
| print("This number is already chosen. Try another.") | ||
| cislo = zadej_cislo() | ||
| vybrane_cisla.append(cislo) | ||
|
|
||
| vybrane_cisla.sort() | ||
| print(f"Vybraná čísla: {vybrane_cisla}") | ||
|
|
||
| vylosovana_cisla = random.sample(range(1, 50), 6) | ||
| vylosovana_cisla.sort() | ||
| print(f"Vylosovaná čísla: {vylosovana_cisla}") | ||
|
|
||
| shodna_cisla = set(vybrane_cisla) & set(vylosovana_cisla) | ||
|
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. ty z toho delas sety, to ma byt spis opacne ze do setu ukaldas.. |
||
|
|
||
| print(f"Počet shodných čísel: {len(shodna_cisla)}") | ||
| print(f"Shodná čísla: {shodna_cisla}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| hra_lotto() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import random | ||
| def lotto_game(): | ||
| user_numbers = set() | ||
|
|
||
| while len(user_numbers) < 6: | ||
| try: | ||
| user_input = int(input("Zadejte číslo (1-49): ")) | ||
| if 1 <= user_input <= 49 and user_input not in user_numbers: | ||
| user_numbers.add(user_input) | ||
| else: | ||
| print("Neplatný vstup, zadejte platné číslo v rozsahu 1-49.") | ||
| except ValueError: | ||
| print("Neplatný vstup, zadejte platné číslo v rozsahu 1-49.") | ||
|
|
||
| sorted_user_numbers = sorted(user_numbers) | ||
| print("Vaše vybraná čísla:", sorted_user_numbers) | ||
|
|
||
| drawn_numbers = set(random.sample(range(1, 50), 6)) | ||
| print("Vylosovaná čísla:", drawn_numbers) | ||
|
|
||
| matched_numbers = set(sorted_user_numbers).intersection(drawn_numbers) | ||
| print("Počet shodných čísel:", len(matched_numbers)) | ||
|
|
||
| if __name__ == "__main__": | ||
| lotto_game() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import random | ||
|
|
||
| def guessing_number2(): | ||
| print("Myslim na cislo mezi 1 a 1000.") | ||
| nejnizsi = 1 | ||
| nejvyssi = 1000 | ||
| pokusy = 10 | ||
|
|
||
| for i in range(pokusy): | ||
| hadane_cislo = random.randint(nejnizsi, nejvyssi) | ||
| print(f"Pocitac hada: {hadane_cislo}") | ||
|
|
||
| odpoved = input("Cislo je prilis male (m), prilis velke (v) nebo vyhravate (s): ") | ||
|
|
||
| if odpoved == "m": | ||
| nejnizsi = hadane_cislo + 1 | ||
| elif odpoved == "v": | ||
| nejvyssi = hadane_cislo - 1 | ||
| elif odpoved == "s": | ||
| print("Pocitac vyhral!") | ||
| break | ||
| else: | ||
| print("Neplatna odpoved. Zadejte 'm' pro prilis male, 'v' pro prilis velke nebo 's' pro vyhravate.") | ||
|
|
||
| else: | ||
| print("Maximalni pocet pokusu. Vyhravate!") | ||
|
|
||
| if __name__ == "__main__": | ||
| guessing_number2() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| from flask import Flask, request | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| HTML_START = """ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Hadejte cislo</title> | ||
| </head> | ||
| <body> | ||
| <h1>Myslete na cislo mezi 1 a 1000</h1> | ||
| <h3>Nerikejte vase cislo ;)</h3> | ||
| <form action="" method="POST"> | ||
| <input type="hidden" name="min" value="{}"></input> | ||
| <input type="hidden" name="max" value="{}"></input> | ||
| <input type="submit" value="OK"> | ||
| </form> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
|
|
||
| HTML = """ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Hadejte cislo</title> | ||
| </head> | ||
| <body> | ||
| <h1>Je vase cislo {guess}?</h1> | ||
| <form action="" method="POST"> | ||
| <input type="submit" name="user_answer" value="prilis velke"> | ||
| <input type="submit" name="user_answer" value="prilis male"> | ||
| <input type="submit" name="user_answer" value="vyhral/a jste"> | ||
| <!-- <input type="submit" name="user_answer" value="vyhral/a jste"> --> | ||
| <input type="hidden" name="min" value="{min}"> | ||
| <input type="hidden" name="max" value="{max}"> | ||
| <input type="hidden" name="guess" value="{guess}"> | ||
| </form> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
|
|
||
| HTML_WIN = """<!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Hadejte cislo</title> | ||
| </head> | ||
| <body> | ||
| <h1>Huraaa! Uhodl jsem! Vase cislo je {guess}</h1> | ||
|
|
||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
|
|
||
| @app.route("/", methods=["GET", "POST"]) | ||
| def hadejte_cislo(): | ||
| if request.method == "GET": | ||
| return HTML_START.format(0, 1001) | ||
| else: | ||
| min_number = int(request.form.get("min")) | ||
| max_number = int(request.form.get("max")) | ||
| user_answer = request.form.get("user_answer") | ||
| guess = int(request.form.get("guess", 500)) | ||
|
|
||
| if user_answer == "prilis velke": | ||
| max_number = guess | ||
| elif user_answer == "prilis male": | ||
| min_number = guess | ||
| elif user_answer == "vyhral/a jste": | ||
| return HTML_WIN.format(guess=guess) | ||
|
|
||
| guess = (max_number - min_number) // 2 + min_number | ||
|
|
||
| return HTML.format(guess=guess, min=min_number, max=max_number) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| app.run() |
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.
ne takle ne, ty to mas udelat pres exception