-
Notifications
You must be signed in to change notification settings - Fork 16
Pull Request na vypracovani workshopu uzivatelem d4ny4bl3 #14
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
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,24 @@ | ||
| from random import randint | ||
|
|
||
|
|
||
| def guessing_game(): | ||
| number = int(randint(1, 100)) | ||
|
|
||
| while True: | ||
| guess = input("Guess the number: ") | ||
|
|
||
| try: | ||
| guess = int(guess) | ||
| if guess < number: | ||
| print("Too small!") | ||
| elif guess > number: | ||
| print("Too big!") | ||
| else: | ||
| print("You win!") | ||
| break | ||
| except ValueError: | ||
| print("It's not a number!") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| guessing_game() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from random import shuffle | ||
|
|
||
|
|
||
| def user_guess(): | ||
| user_guess = [] | ||
| order = 1 | ||
| while len(user_guess) != 6: | ||
| try: | ||
| num = int(input(f"Enter {order}. number: ")) | ||
| if num in user_guess: | ||
| print("You entered the same number!") | ||
| # user_guess = sorted(user_guess) | ||
| print(f"Your numbers are currently: {tuple(sorted(user_guess))}") | ||
| elif num < 1 or num > 49: | ||
|
Author
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. validitu vstupu je dobre predradit jakekoli jine kontrole |
||
| print("Enter a number between 1-49") | ||
| else: | ||
| user_guess.append(num) | ||
| order += 1 | ||
| except ValueError: | ||
| print("Must entered a number!") | ||
| return user_guess | ||
|
|
||
|
|
||
| def lotto_numbers(): | ||
| numbers = [i for i in range(1, 50)] | ||
| shuffle(numbers) | ||
| numbers = numbers[:6] | ||
| return numbers | ||
|
|
||
|
|
||
| def format_numbers(numbers): | ||
| print(", ".join(str(i) for i in sorted(numbers))) | ||
|
|
||
|
|
||
| def lotto(): | ||
| matched_numbers = [] | ||
| count = 0 | ||
| user_numbers = user_guess() | ||
| lotto_num = lotto_numbers() | ||
| print("\nYour numbers:") | ||
| format_numbers(user_numbers) | ||
| print("Lotto numbers: ") | ||
| format_numbers(lotto_num) | ||
| for i in user_numbers: | ||
| if i in lotto_num: | ||
| count += 1 | ||
| matched_numbers.append(i) | ||
|
|
||
| if count >= 1: | ||
| print(f"Matched numbers: ") | ||
| format_numbers(matched_numbers) | ||
| if count == 1: | ||
| print(f"You guessed {count} number!") | ||
| else: | ||
| print(f"You guessed {count} numbers!") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| lotto() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| def answer(): | ||
| posibble_answer = ["too small", "too big", "you win"] | ||
| while True: | ||
| user_answer = input("Is this a correct guess?: ") | ||
| user_answer.lower() | ||
| if user_answer in posibble_answer: | ||
| break | ||
| else: | ||
| print("You can only write 'too big', too small', 'you win')") | ||
| return user_answer | ||
|
|
||
|
|
||
| def guessing_game(): | ||
| print("Think about a number from 0 to 100 and let me guess it!") | ||
| print("You can only write 'too big', too small', 'you win')") | ||
| min_num = 0 | ||
| max_num = 1000 | ||
| user_answer = "" | ||
| while True: | ||
| guess = int((max_num - min_num) / 2) + min_num | ||
| print(f"Guessing: {guess}") | ||
| user_answer = answer() | ||
| if user_answer == "too big": | ||
| max_num = guess | ||
| elif user_answer == "too small": | ||
| min_num = guess | ||
| elif user_answer == "you win": | ||
| print("I won!") | ||
| break | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| guessing_game() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from flask import Flask, request, render_template | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
|
|
||
| @app.route("/") | ||
| def guessing_game(): | ||
| return render_template("index.html", min=0, max=1000, guess=500, condition=False) | ||
|
|
||
|
|
||
| @app.route("/", methods=["POST"]) | ||
| def guessing_game_post(): | ||
| min_number = int(request.form["min"]) | ||
| max_number = int(request.form["max"]) | ||
| user_input = request.form["user_input"] | ||
| guess = int(request.form["guess"]) | ||
| condition = False | ||
|
|
||
| if user_input == "Too small": | ||
| min_number = guess | ||
| elif user_input == "Too big": | ||
| max_number = guess | ||
| elif user_input == "You win": | ||
| condition = True | ||
| return render_template("index.html", guess=guess, condition=condition) | ||
|
|
||
| guess = int(((max_number - min_number) / 2) + min_number) | ||
|
|
||
| return render_template("index.html", min=min_number, max=max_number, guess=guess, condition=condition) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run(debug=True) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Guessing game</title> | ||
| </head> | ||
| <body> | ||
| {% if not condition %} | ||
| <h1>Think about a number from 0 to 100 and let me guess it!</h1> | ||
|
|
||
| <h2>My guess: {{ guess }} </h2> | ||
|
|
||
| <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" value="{{min}}"> | ||
| <input type="hidden" name="max" value="{{max}}"> | ||
| <input type="hidden" name="guess" value="{{guess}}"> | ||
| </form> | ||
| {% else %} | ||
| <h1>I Won! Your number was {{ guess }}</h1> | ||
| {% endif %} | ||
|
|
||
| {% print(min_num) %} | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from random import randint | ||
|
|
||
| dice = ("D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100") | ||
|
|
||
|
|
||
| def format_dice(dice): | ||
| dice_split = dice.split("D") | ||
| if len(dice_split) != 2: | ||
| print("Wrong format of dice") | ||
| number_of_rolls, type_and_modifier = dice_split | ||
|
|
||
| if not number_of_rolls: | ||
| number_of_rolls = 1 | ||
|
|
||
| if "+" in type_and_modifier: | ||
| x = type_and_modifier.split("+") | ||
| type_of_dice, modifier = map(int, x) # type_of_dice, modifier = x | ||
|
Author
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. hezky! |
||
| print(f"+: {number_of_rolls, type_of_dice, modifier}") | ||
| print(f"Type +: number_of_rolls", type(type_of_dice)) | ||
| print(f"Type +: type_of_dice", type(modifier)) | ||
| print(f"Type +: modifier", type(modifier)) | ||
| return number_of_rolls, type_of_dice, modifier | ||
| elif "-" in type_and_modifier: | ||
| x = type_and_modifier.split("-") | ||
| type_of_dice, modifier = map(int, x) | ||
| print(f"-: {number_of_rolls, type_of_dice, modifier}") | ||
| print(f"Type -: number_of_rolls", type(type_of_dice)) | ||
| print(f"Type -: type_of_dice", type(modifier)) | ||
| print(f"Type -: modifier", type(modifier)) | ||
| return number_of_rolls, type_of_dice, -modifier | ||
|
|
||
| print(f"Type d6 number:", type(number_of_rolls)) | ||
| print(f"Type d6 type:", type(type_and_modifier)) | ||
|
|
||
| return number_of_rolls, type_and_modifier, None | ||
|
|
||
|
|
||
| def roll_the_dice(): | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| roll = input("Enter a roll the dice: ").upper() | ||
| print(format_dice(roll)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from random import randint | ||
|
|
||
| dice = ("D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100") | ||
|
|
||
|
|
||
| def roll_the_dice(input_dice): | ||
| for cube in dice: | ||
| if cube in input_dice: | ||
| try: | ||
| number_of_rolls, modifier = input_dice.split(cube) | ||
| except ValueError: | ||
| return "Wrong Dice" | ||
| type_of_dice = cube[1:] | ||
| break | ||
| else: | ||
| return "Wrong dice" | ||
|
|
||
| if number_of_rolls == "": | ||
|
Author
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. doporuil bych spis |
||
| number_of_rolls = 1 | ||
|
|
||
| if modifier == "": | ||
| modifier = 0 | ||
|
|
||
| number_of_rolls, type_of_dice, modifier = map(int, [number_of_rolls, type_of_dice, modifier]) | ||
|
|
||
| # dice_sum = 0 | ||
| # for i in range(number_of_rolls): | ||
| # dice_sum += randint(1, type_of_dice) | ||
| # | ||
| # calculation1 = dice_sum + modifier | ||
| # print(f"Calculation1: {calculation1}") | ||
|
|
||
| calculation = sum([randint(1, type_of_dice) for i in range(number_of_rolls)]) + modifier | ||
|
|
||
| return f"The Result of the dice roll {input_dice} is {calculation}" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print(roll_the_dice("2D6+4")) | ||
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.
Chybi kontrola validity vstupu