-
Notifications
You must be signed in to change notification settings - Fork 16
snad uz to projde cervi dirou #12
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
Open
Libbaka
wants to merge
6
commits into
CodersLab-CZ:master
Choose a base branch
from
Libbaka:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| 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() | ||
This file contains hidden or 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
| 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) | ||
|
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. delas intersection takze proc nezvit ten puvodni >> |
||
| print("Počet shodných čísel:", len(matched_numbers)) | ||
|
|
||
| if __name__ == "__main__": | ||
| lotto_game() | ||
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from flask import Flask, render_template | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| class DiceException(Exception): | ||
| pass | ||
|
|
||
| def throw_dice(): | ||
| return random.randint(1, 6) + random.randint(1, 6) | ||
|
|
||
| def play_turn(): | ||
| result = throw_dice() | ||
|
|
||
| if result == 7: | ||
| raise DiceException("// 7") | ||
| elif result == 11: | ||
| raise DiceException(" * 11") | ||
| else: | ||
| return result | ||
|
|
||
| def play_game(): | ||
| player_scores = [0, 0] | ||
|
|
||
| while max(player_scores) < 2001: | ||
| try: | ||
| player_scores[0] += play_turn() | ||
| player_scores[1] += play_turn() | ||
| except DiceException as e: | ||
| return None, str(e) | ||
|
|
||
| winner = player_scores.index(max(player_scores)) + 1 | ||
| return winner, max(player_scores) | ||
|
|
||
| @app.route('/') | ||
| def index(): | ||
| return render_template('index.html') | ||
|
|
||
| @app.route('/play', methods=['POST']) | ||
| def play(): | ||
| winner, score = play_game() | ||
| if winner is not None: | ||
| return f"Hráč {winner} vyhrál s celkovým skóre {score}!" | ||
| else: | ||
| return f"Chyba: {score}" | ||
|
|
||
| if __name__ == "__main__": | ||
| app.run(debug=True) | ||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import re | ||
| import random | ||
|
|
||
| def roll_dice(code): | ||
| pattern = re.compile(r'(\d*)[dD]([3-9]|10|12|20|100)([+\-]\d+)?') | ||
|
|
||
| match = pattern.match(code) | ||
| if not match: | ||
| return "Neplatny kod kostky." | ||
|
|
||
| num_rolls = int(match.group(1)) if match.group(1) else 1 | ||
| dice_type = int(match.group(2)) | ||
| modifier = int(match.group(3)) if match.group(3) else 0 | ||
|
|
||
| result = sum(random.randint(1, dice_type) for _ in range(num_rolls)) + modifier | ||
|
|
||
| return f"Vysledek hodu kostkou ({num_rolls}D{dice_type}{modifier}): {result}" | ||
|
|
||
| #priklad | ||
| kod_kostky = input("Zadejte kod kostky (napr. 2D10+10): ") | ||
| vysledek_hodu = roll_dice(kod_kostky) | ||
| print(vysledek_hodu) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ten try je prilis sirokej a lepsi to omezit jen na ten kus kodu kde cekas ze to vyhdi vyjimku