-
Notifications
You must be signed in to change notification settings - Fork 16
workshop jp #8
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 jp #8
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,32 @@ | ||
| from random import randint | ||
|
|
||
| def comparsion(user_number, pc_number): | ||
| """ The function compare pc_number and user_number and return result of comparsion.""" | ||
|
|
||
| if user_number < pc_number: | ||
| return "Too small!" | ||
|
|
||
| elif user_number > pc_number: | ||
| return "Too big!" | ||
|
|
||
| return "You win!" | ||
|
|
||
| pc_number = randint(1,100) | ||
| print(pc_number) | ||
|
|
||
| win="" | ||
| while win != "You win!": | ||
| print(f"Guess the number from 1 to 100.") | ||
| user_number = input("Guess the number: ") | ||
|
|
||
| try: | ||
| user_number = int(user_number) | ||
|
|
||
| if not 0 <= user_number <= 101: | ||
| print(f"It's not a number from 1 to 100!") | ||
| else: | ||
| win = comparsion(user_number, pc_number) | ||
| print(win) | ||
|
|
||
| except ValueError: | ||
| print(f"It's not a number!") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from random import sample | ||
| import os | ||
|
|
||
| def print_fortune(fortune): | ||
| os.system("clear") | ||
| for i in range(0, len(fortune), 5): | ||
| print(*fortune[i:i+5]) | ||
|
|
||
| def select_number(): | ||
| os.system("clear") | ||
| # fortune = [i for i in range(1,50)] | ||
| fortune = list(range(1,50)) | ||
| select_numbers = [] | ||
| count = 0 | ||
|
|
||
| # while not count == 6: | ||
| while count < 6: | ||
|
|
||
| print_fortune(fortune) | ||
| print("") | ||
| print(f"Your select numbers are:") | ||
| print(*select_numbers) | ||
| select = input(f"Select {count + 1}. number out of 6, from 1 to 49: ") | ||
|
|
||
|
|
||
| try: | ||
| select = int(select) | ||
|
|
||
| if 1 <= select <= 49: | ||
| if select not in select_numbers: | ||
| select_numbers.append(fortune.pop(select - 1)) | ||
| select_numbers.sort() | ||
|
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. v kazde iteraci sortujes - to neni potreba. sort se muze udelat jednou a na konci |
||
| if (select - 1) >= 8: | ||
|
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. co je tady ta 8? |
||
| fortune.insert(select - 1, "X ") | ||
| count += 1 | ||
| else: | ||
| fortune.insert(select - 1, "X") | ||
| count += 1 | ||
|
|
||
|
|
||
| except ValueError: | ||
| pass | ||
|
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. proc to vlastn echytas kdyz tu vyjimku umlcis? |
||
|
|
||
| print_fortune(fortune) | ||
| print("") | ||
| print(f"Your select numbers are:") | ||
| print(*select_numbers) | ||
|
|
||
|
|
||
| random_indexes = sorted(sample(range(len(fortune)), 6)) | ||
| print("") | ||
| print("The winning numbers are:") | ||
| for lucky_numbers in random_indexes: | ||
| print(lucky_numbers +1, end=" ") | ||
| print("") | ||
|
|
||
| sum_win_numbers = 0 | ||
| for index in random_indexes: | ||
| if index <= 9 and fortune[index] == "X": | ||
| print("X", end=" ") | ||
| sum_win_numbers += 1 | ||
|
|
||
| if index >= 10 and fortune[index] == "X ": | ||
| print("X ", end=" ") | ||
| sum_win_numbers += 1 | ||
|
|
||
| if index >= 10 and not fortune[index] == "X ": | ||
| print("- ", end=" ") | ||
|
|
||
| if index <= 9 and not fortune[index] == "X": | ||
| print("-", end=" ") | ||
|
|
||
| print("") | ||
| if 6 >= sum_win_numbers >=3: | ||
| return f"**** You won! ***\nYou guessed it.\nThe number of guessed numbers is {sum_win_numbers}" | ||
|
|
||
| return f"Unfortunately, you didn't win.\nThe number of guessed numbers is less than 3.\nThe number of guessed numbers is {sum_win_numbers}." | ||
|
|
||
| print(select_number()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from random import randint | ||
| import os | ||
|
|
||
| min_number = 0 | ||
| max_number = 1000 | ||
|
|
||
| ai_number = randint(0, 1000) | ||
|
|
||
| def mathematics(): | ||
| return (min_number + max_number) // 2 | ||
|
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 bych teda do funkce nedaval |
||
|
|
||
| def compare(ai_number, user_answer): | ||
| global min_number, max_number | ||
|
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. nepouzivat globalni prommene! to neni vubec potreba |
||
|
|
||
| if user_answer == 1: | ||
| min_number = ai_number | ||
| return mathematics() | ||
|
|
||
| elif user_answer == 2: | ||
| max_number = ai_number | ||
| return mathematics() | ||
|
|
||
| def clear(): | ||
| os.system("clear") | ||
|
|
||
| def lyar(): | ||
| clear() | ||
| input(f"Don't cheat!\nPress Enter to continue...") | ||
|
|
||
|
|
||
| while True: | ||
| try: | ||
| clear() | ||
| user_number = int(input(f"Think about a number from 1 to 1000 and let me guess it!\nPlease enter your number: ")) | ||
| if 1 <= user_number <= 1000: | ||
| break | ||
| else: | ||
| clear() | ||
| input(f"Please enter a number within the range of 1 to 1000.\nPress Enter to continue...") | ||
| except ValueError: | ||
| clear() | ||
| input(f"Please enter a valid integer.\nPress Enter to continue...") | ||
|
|
||
| while True: | ||
|
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. velmi velmi velmi komplikovana logika. vubec nevim co se deje. ten algoritmus je pomerne primocary - je to klasicky binary search |
||
| clear() | ||
| print(f"User number: {user_number}\n") | ||
| print(f"AI guessed: {ai_number}\n") | ||
|
|
||
| try: | ||
| user_answer = int(input(f"Your answer for AI:\n\n1 for AI number is too low\n2 for AI number too high\n3 for AI number same with your\n\nEnter the number of answer: ")) | ||
|
|
||
| if user_answer not in [1, 2, 3]: | ||
| input(f"Please enter 1, 2, or 3.\nPress Enter to continue...") | ||
|
|
||
| if (ai_number > user_number and user_answer == 1) or (ai_number < user_number and user_answer == 2) or ((ai_number != user_number) and user_answer == 3) or (ai_number == user_number and (user_answer == 1 or user_answer == 2)): | ||
|
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. ufffff ne. tohle opravdu ne.. takle slozite napsane jsem to jeste nevidel. takle to nemuzes mit
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. Mne je z toho taky blujno ale ve 2 rano jsem se na tomhle nejak zasekl a jine reseni mne nenapadlo ..... a do GPT at to zjednoduzsi to davat nechci ...vratim se k tomu a zkusim to jinak |
||
| lyar() | ||
|
|
||
| elif user_answer in [1, 2]: | ||
| ai_number = compare(ai_number, user_answer) | ||
| else: | ||
| clear() | ||
| print(f"AI wins! Your number was {user_number}.") | ||
| exit(0) | ||
|
|
||
| except ValueError: | ||
| pass | ||
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,84 @@ | ||
| from flask import Flask, render_template | ||
|
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. tady pro to plati v podstate to same co nahore - je to super komplikovane a neni to spravne |
||
| from flask import request | ||
| from random import randint | ||
| app = Flask(__name__) | ||
|
|
||
| global min_number | ||
| global max_number | ||
| global ai_number | ||
|
|
||
| min_number = 0 | ||
| max_number = 1000 | ||
| ai_number = randint(0, 1000) | ||
|
|
||
|
|
||
| def mathematics(): | ||
| return (min_number + max_number) // 2 | ||
|
|
||
|
|
||
| @app.route('/winner.html',methods=['POST']) | ||
| def restart_game(): | ||
| return render_template('index.html') | ||
|
|
||
| # return render_template('index.html') | ||
| # user_number = int(request.form['user_number']) | ||
| # math() | ||
|
|
||
|
|
||
| @app.route('/game.html', methods=['GET', 'POST']) | ||
| def math(): | ||
| global min_number | ||
| global max_number | ||
| global ai_number | ||
| if request.method == 'POST': | ||
| action = request.form['action'] | ||
| user_number = int(request.form['user_number']) | ||
| ai_number = int(request.form['ai_number']) | ||
|
|
||
| if (ai_number > user_number and action == 'small') or (ai_number < user_number and action == 'big') or ((ai_number != user_number) and action == 'same') or (ai_number == user_number and (action == 'small' or action == 'big')): | ||
| return render_template('game.html', user_number=user_number, ai_number=ai_number, min_number=min_number, max_number=max_number, show_text=True) | ||
|
|
||
| else: | ||
| if action == 'small': | ||
| min_number = ai_number | ||
| ai_number = mathematics() | ||
| return render_template('game.html', user_number=user_number, ai_number=ai_number, min_number=min_number, max_number=max_number, show_text=False) | ||
|
|
||
| elif action == 'big': | ||
| max_number = ai_number | ||
| ai_number = mathematics() | ||
| return render_template('game.html', user_number=user_number, ai_number=ai_number, min_number=min_number, max_number=max_number, show_text=False) | ||
|
|
||
| elif action == 'same': | ||
| return render_template('winner.html', user_number=user_number) | ||
|
|
||
|
|
||
| @app.route('/index.html', methods=['POST']) | ||
| def user_number(): | ||
| global min_number | ||
| global max_number | ||
| global ai_number | ||
| min_number = 0 | ||
| max_number = 1000 | ||
|
|
||
| ai_number = randint(0, 1000) | ||
| user_number = int(request.form['user_number']) | ||
| return render_template('game.html', ai_number=ai_number, user_number=user_number, min_number=min_number, max_number=max_number, show_text = False) | ||
|
|
||
|
|
||
| @app.route('/') | ||
| def index(): | ||
| return render_template('index.html') | ||
| # global min_number | ||
| # global max_number | ||
| # global ai_number | ||
| # min_number = 0 | ||
| # max_number = 1000 | ||
| # | ||
| # ai_number = randint(0, 1000) | ||
| # return render_template('index.html') | ||
| # user_number = int(request.form['user_number']) | ||
| # math() | ||
|
|
||
|
|
||
| app.run(debug=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Guess the Number Game</title> | ||
| </head> | ||
| <body> | ||
| <h1>Guess the Number Game</h1> | ||
|
|
||
| <form method="post" action="{{ url_for('math') }}"> | ||
|
|
||
| <p>Your number is: <input type="number" name="user_number" value="{{ user_number }}" readonly></p> | ||
| <p>AI guess number is: <input type="number" name="ai_number" value="{{ ai_number }}" readonly></p> | ||
| <br><br> | ||
| <input type="hidden" name="min_number" value="{{min_number}}"> | ||
| <input type="hidden" name="max_number" value="{{max_number}}"> | ||
| <br><br> | ||
| <p>AI number is to: </p> | ||
| <input type="submit" name="action" value="small"> | ||
| <input type="submit" name="action" value="big"> | ||
| <input type="submit" name="action" value="same"> | ||
| <br><br> | ||
| {% if show_text %} | ||
| <h1>Don't cheat!</h1> | ||
| {% endif %} | ||
| <br><br> | ||
| </form> | ||
| </body> | ||
| </html> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Guess the Number Game</title> | ||
| </head> | ||
| <body> | ||
| <h1>Guess the Number Game</h1> | ||
| <form method="post" action="{{ url_for('user_number') }}"> | ||
| <p>Guess a number between 1 and 1000:</p> | ||
| <input type="number" name="user_number" min="1" max="1000" required> | ||
| <input type="hidden" name="min_number" value="{{min_number}}"> | ||
| <input type="hidden" name="max_number" value="{{max_number}}"> | ||
| <br><br> | ||
| <input type="submit"> | ||
| </form> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>The computer guessed your number.</title> | ||
| </head> | ||
| <body> | ||
| <h1>The computer guessed your number. It was number {{user_number}}.</h1> | ||
| <p>Play again?</p> | ||
| <form method="post" action="{{ url_for('restart_game') }}"> | ||
| <input type="submit" value="Ano"> | ||
| </form> | ||
| </body> | ||
| </html> |
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.
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.
opet je to velmi komplikvane ta logika. vzdyt jenom vybiras par cisel.. to nemusi a nema byt takhle prekomplikvane