-
Notifications
You must be signed in to change notification settings - Fork 16
pokus o workshop #13
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
Satircz
wants to merge
6
commits into
CodersLab-CZ:master
Choose a base branch
from
Satircz: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
pokus o workshop #13
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4ca0181
První pokus o první ukol z workshopu
Satircz fce9453
První pokus splnění prvního ukolu workshopu
Satircz 736f112
tak tady nevím jak dál, porovnani
Satircz 8456d9b
done
Satircz 44fa64f
done too
Satircz 9a3705d
těžký ale done
Satircz 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,44 @@ | ||
| from random import randint | ||
|
|
||
|
|
||
| def guessing_game(): | ||
| random_number = randint(1, 100) | ||
| print(random_number) | ||
| """Vytiskne vybrané číslo, | ||
| pro kontrolu při psaní kodů | ||
| """ | ||
| while True: | ||
| try: | ||
| guess_number: int = int(input("\nPlease, insert your guess number from 1-100: ")) | ||
| except ValueError: | ||
| print("is not a number, guess number again!") | ||
| continue | ||
|
|
||
| print(f"Your guessed number is {guess_number}.") | ||
| if guess_number < random_number: | ||
| print("Too small!, try again!") | ||
| elif guess_number > 100: | ||
| print("You are out of range, choose 1-100!") | ||
| elif guess_number > random_number: | ||
| print("Too Big!Try again") | ||
| elif guess_number == random_number: | ||
| print(f"Guessed number was {guess_number} and you Win") | ||
| while True: | ||
| play_again = input("Do you want play again ? Y/N: ") | ||
| cap_play_again = play_again.capitalize() | ||
| if cap_play_again == "Y": | ||
| random_number = randint(1, 100) | ||
| print(f"\n{random_number}") | ||
| """Vytiskne vybrané číslo, | ||
| pro kontrolu při psaní kodů | ||
| """ | ||
| guess_number = None | ||
| elif cap_play_again == "N": | ||
| print("Thank you, Bye Bye") | ||
| break | ||
| else: | ||
| print("invalid input, please input Y or N") | ||
| continue | ||
|
|
||
|
|
||
| guessing_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,48 @@ | ||
| import random | ||
|
|
||
|
|
||
|
|
||
|
|
||
| def guess_numbers() -> object: | ||
| user_numbers = [] | ||
| while len(user_numbers) < 6: | ||
| user_guess = input("Guess number from 1 to 49: ") | ||
|
|
||
| if not user_guess.isdigit(): | ||
| print("You need enter a valid number.") | ||
| continue | ||
| number = int(user_guess) | ||
| if number < 1 or number > 49: | ||
|
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. Opet - kontrolu validity je potreba predradit kontrole herni. |
||
| print("You need enter number from 1-49") | ||
| continue | ||
| if number in user_numbers: | ||
| print("your number is already guessed") | ||
| continue | ||
| user_numbers.append(number) | ||
| user_numbers.sort() | ||
| return user_numbers | ||
|
|
||
|
|
||
| def lotto(): | ||
| lotto_numbers = sorted(random.sample(range(1, 50), 6)) | ||
| return lotto_numbers | ||
|
|
||
|
|
||
| def result(): | ||
| user_numbers = guess_numbers() | ||
| print(f"User Numbers: {user_numbers}") | ||
| lotto_numbers = lotto() | ||
| print(f"LOTTO Numbers: {lotto_numbers}") | ||
| matched_numbers: int = 0 | ||
| for num in user_numbers: | ||
| if num in lotto_numbers: | ||
| matched_numbers += 1 | ||
| return f"You get {matched_numbers} from {lotto_numbers}" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("Welcome in LOTTO GAME") | ||
| name = input("Enter your name: ") | ||
| print(f"Hi {name}, you need to choose 6 numbers from 1 to 49. Can you guess all 6?") | ||
| print(result()) | ||
|
|
||
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,45 @@ | ||
| import random | ||
|
|
||
| def get_user_numbers(): | ||
| user_numbers = [] | ||
| while len(user_numbers) < 6: | ||
| user_input = input("Enter a number (1-49): ") | ||
| if not user_input.isdigit(): | ||
| print("Please enter a valid number.") | ||
| continue | ||
| number = int(user_input) | ||
| if number < 1 or number > 49: | ||
| print("Number must be in the range of 1-49.") | ||
| continue | ||
| if number in user_numbers: | ||
| print("Number already entered.") | ||
| continue | ||
| user_numbers.append(number) | ||
| user_numbers.sort() | ||
| return user_numbers | ||
|
|
||
| def generate_lottery_numbers(): | ||
| return sorted(random.sample(range(1, 50), 6)) | ||
|
|
||
| def check_matching_numbers(user_numbers, lottery_numbers): | ||
| matches = 0 | ||
| for num in user_numbers: | ||
| if num in lottery_numbers: | ||
| matches += 1 | ||
| return matches | ||
|
|
||
| def main(): | ||
|
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. pekne rozdeleni funkcionalit! |
||
| print("Welcome to the LOTTO game!") | ||
| print("Please enter 6 numbers.") | ||
|
|
||
| user_numbers = get_user_numbers() | ||
| print("Your numbers:", user_numbers) | ||
|
|
||
| lottery_numbers = generate_lottery_numbers() | ||
| print("Lottery numbers:", lottery_numbers) | ||
|
|
||
| matched_numbers = check_matching_numbers(user_numbers, lottery_numbers) | ||
| print("You have matched", matched_numbers, "numbers.") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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,35 @@ | ||
| import random | ||
|
|
||
|
|
||
| def user_input(): | ||
| possible_input = ["too small", "too big", "you win"] | ||
| while True: | ||
| user_answer = input().lower() | ||
| if user_answer in possible_input: | ||
| break | ||
| print("Input is no in ['too small', 'too big', 'you win']") | ||
| return user_answer | ||
|
|
||
|
|
||
| def guess_game(): | ||
| print("Think about a number from 0 to 1000 and let me guess it!") | ||
| print("Write number and press 'Enter' to continue") | ||
| input() | ||
| min_number = 0 | ||
| max_number = 1000 | ||
| user_answer = "" | ||
| while user_answer != "you win": | ||
| guess = int((max_number - min_number) // 2 + min_number) | ||
| print(f"Your number is: {guess}") | ||
| user_answer = user_input() | ||
| if user_answer == "too big": | ||
| max_number = guess | ||
| if user_answer == "too small": | ||
| min_number = guess | ||
|
|
||
| print("You Win!") | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print(guess_game()) |
Binary file not shown.
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,34 @@ | ||
| from flask import Flask, request, render_template | ||
|
|
||
|
|
||
| app = Flask(__name__) | ||
| min_guess = 0 | ||
| max_guess = 1000 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| @app.route("/") | ||
| def guess_number(): | ||
| global min_guess, max_guess | ||
| return render_template("get.html",min_guess=min_guess, max_guess=max_guess, new_guess=500) | ||
|
|
||
| @app.route("/", methods=["POST"]) | ||
| def guessing_numbers(): | ||
| global min_guess, max_guess | ||
| current = int(((max_guess - min_guess) / 2) + min_guess) | ||
| user_input = request.form["user_input"] | ||
| if user_input == "too big": | ||
| max_guess = current | ||
| elif user_input == "too small": | ||
| min_guess = current | ||
| else: | ||
| return "You WIN" | ||
|
|
||
| new_guess = int(((max_guess - min_guess) / 2) + min_guess) | ||
| return render_template("get.html", min_guess=min_guess, max_guess=max_guess, new_guess=new_guess) | ||
|
|
||
|
|
||
|
|
||
| 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,18 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>guess the number</title> | ||
| </head> | ||
| <body> | ||
| <h1>Its a number {{new_guess}} ?</h1> | ||
| <form action="/" method="POST"> | ||
| <input type="submit" name="user_input" value="too big"> | ||
| <input type="submit" name="user_input" value="too small"> | ||
| <input type="submit" name="user_input" value="you win"> | ||
| <input type="hidden" name="min_guess" value="{{min_guess}}"> | ||
| <input type="hidden" name="max_guess" value="{{max_guess}}"> | ||
| <input type="hidden" name="new_guess" value="{{new_guess}}"> | ||
| </form> | ||
| </body> | ||
| </html> |
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,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Guess The Number</title> | ||
| </head> | ||
| <body> | ||
| <h1>Imagine a number between 0 and 1000</h1> | ||
| <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> |
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.
doporucil bych delat tento check prvni a nedavat ho do elif ale do sveho vlastniho if