From be1ffeafce0785b2b6c01bc103739fb3683d1ec1 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Tue, 30 Jan 2024 11:39:34 +0100 Subject: [PATCH 01/15] =?UTF-8?q?test=20p=C5=99ipojen=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1] guessing game/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1] guessing game/main.py b/1] guessing game/main.py index e69de29..4f282dd 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -0,0 +1 @@ +print("Testuji propojení repozitáře.") \ No newline at end of file From 8fa64c0e547c2b58fb38b555396a10638b990818 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Wed, 31 Jan 2024 14:47:23 +0100 Subject: [PATCH 02/15] first example finish --- 1] guessing game/README.md | 23 ++++++++++++++++++++++ 1] guessing game/main.py | 39 +++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 1] guessing game/README.md diff --git a/1] guessing game/README.md b/1] guessing game/README.md new file mode 100644 index 0000000..b3ba242 --- /dev/null +++ b/1] guessing game/README.md @@ -0,0 +1,23 @@ +## GUESSING GAME + +Symple console application for guessing numbers. + + +# Lauched application + +Use the "cd" command to navigate to the "1] guessing game" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +The application generates a random number between 1 and 100. The player tries to guess this number. + +The application prompts the user to enter an integer. If the player enters letters or floats, the app will ask them to correct it. If the entered number is higher or lower than the selected number, the application will alert the player. When the player guesses the number, the app will tell them and the program will exit. + +If the player wants to quit the application during the game, he can use "CTRL+C". \ No newline at end of file diff --git a/1] guessing game/main.py b/1] guessing game/main.py index 4f282dd..428bc6f 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -1 +1,38 @@ -print("Testuji propojení repozitáře.") \ No newline at end of file +from random import randint + + +def num_guessing_game() -> int: + """ + The function of guessing a random number between 1 and 100. + + The function using randint will generate a number, and using + while loop accepts number tips from the user. once + the user guesses the number, the program ends. + """ + print("Welcome to our guessing game! " + "Can you guess the number between 1 and 100?") + + # getting a random number + wanted_num = randint(1, 101) + + # getting a number of player + while True: + try: + player_num = int(input("Enter whole number: ")) + + # testing a player's number + if player_num < wanted_num: + print("Too small number...") + continue + elif player_num > wanted_num: + print("Too big number...") + continue + else: + return "!!! YOU WIN !!!" + + # wrong value entery check + except ValueError: + print("You entered the wrong value, try again...") + + +print(num_guessing_game()) From 102007037b6dad2decfeb50954c85334608b0617 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Thu, 1 Feb 2024 13:32:47 +0100 Subject: [PATCH 03/15] =?UTF-8?q?vypracov=C3=A1no=20druh=C3=A9=20cvi=C4=8D?= =?UTF-8?q?en=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2] loto/main.py | 75 ++++++++++++++++++++++++++++++++++++ 3] guessing game 2/README.md | 25 ++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 3] guessing game 2/README.md diff --git a/2] loto/main.py b/2] loto/main.py index e69de29..4946943 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -0,0 +1,75 @@ +from random import randint + + +def nums_of_player() -> list: + """ + The function retrieves a list of six original numbers + from the player. + + Funktion checks whether: + player entered integer in range of 1-49, + player has not entered a given number before. + + Funktion return a sorted list of numbers. + """ + # gettint a list of numbers + player_nums = [] + while len(player_nums)<6: + try: + num = int(input(f"Enter number No. {len(player_nums) +1}: ")) + # check a number + if num in player_nums: + print("The number has already been entered. Try again...") + elif num < 1 or num > 49: + print("The number is not in range of 1 - 49. Try again...") + else: + player_nums.append(num) + + except ValueError: + print("Value is not whole number. Try again...") + + player_nums.sort() + return player_nums + + +def winning_nums() -> list: + """ + The function uses randint (Random library) and gets a list + of six original numbers from the range 1-49. + """ + draw_nums = [] + while len(draw_nums) < 6: + draw_nums.append(randint(1, 50)) + + return draw_nums + + +def main(): + """ + The function uses the "nums_of_player()" function and gets the list + numbers from a player. Then uses the "winning_nums()" function and gets + list of drawn numbers. + The function dislays lists of numbers and compares them. Then + displays how many numbers the player guessed. + """ + print(f"WELCOME TO THE PYTHON LOTTERY!\n{'=' * 30}\nWe draw " + "sixt numbers in range of 1-49. Try to guess them...") + + # getting numbers of player + player_nums = nums_of_player() + print(f"Your numbers:\n{', '.join(map(str, player_nums))}") + + # getting winning numbers + draw_nums = winning_nums() + print(f"Winning numbers:\n{', '.join(map(str, draw_nums))}") + + # evaluation of results + hits = 0 + for num in player_nums: + if num in draw_nums: + hits += 1 + separator = "=" * 25 + print(f"{separator}\nSUM OF GUESSED NUMBERS: {hits}\n{separator}") + + +main() diff --git a/3] guessing game 2/README.md b/3] guessing game 2/README.md new file mode 100644 index 0000000..0e52a35 --- /dev/null +++ b/3] guessing game 2/README.md @@ -0,0 +1,25 @@ +## GUESSING GAME + +Symple console application LOTTO simulator. + + +# Lauched application + +Use the "cd" command to navigate to the "2] loto" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +1. The function gets the list numbers from a player and while checks: +- whether the string entered is a valid number, +- whether the user has not entered a given number before, +- if the number is in the range of 1-49. +2. The function uses randint (Random library) and gets a list of six original numbers from the range 1-49. +3. The function dislays list of numbers from player and list of winning numbers and then compares them. +4. The function displays how many numbers the player guessed. \ No newline at end of file From 44de903187c9a81a814d38a96eab48ee2ac53512 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Fri, 2 Feb 2024 15:38:37 +0100 Subject: [PATCH 04/15] =?UTF-8?q?vypracov=C3=A1na=20dal=C5=A1=C3=AD=20cvi?= =?UTF-8?q?=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1] guessing game/README.md | 8 +-- 1] guessing game/main.py | 10 ++-- 2] loto/README.md | 25 +++++++++ 2] loto/main.py | 18 +++---- 3] guessing game 2/README.md | 18 +++---- 3] guessing game 2/main.py | 62 ++++++++++++++++++++++ 4] guessing game 3/README.md | 23 ++++++++ 4] guessing game 3/main.py | 31 +++++++++++ 4] guessing game 3/templates/guessing.html | 20 +++++++ 4] guessing game 3/templates/i_win.html | 19 +++++++ 4] guessing game 3/templates/index.html | 20 +++++++ 5] 2001/README.md | 23 ++++++++ 5] dice/README.md | 23 ++++++++ 13 files changed, 272 insertions(+), 28 deletions(-) create mode 100644 2] loto/README.md create mode 100644 4] guessing game 3/README.md create mode 100644 4] guessing game 3/templates/guessing.html create mode 100644 4] guessing game 3/templates/i_win.html create mode 100644 4] guessing game 3/templates/index.html create mode 100644 5] 2001/README.md create mode 100644 5] dice/README.md diff --git a/1] guessing game/README.md b/1] guessing game/README.md index b3ba242..a3c9c02 100644 --- a/1] guessing game/README.md +++ b/1] guessing game/README.md @@ -1,6 +1,6 @@ ## GUESSING GAME -Symple console application for guessing numbers. +Symple console application for guessing random number in the range 1-100. # Lauched application @@ -16,8 +16,8 @@ for WINDOWS # Running application -The application generates a random number between 1 and 100. The player tries to guess this number. +1. The application generates a random number between 1 and 100. -The application prompts the user to enter an integer. If the player enters letters or floats, the app will ask them to correct it. If the entered number is higher or lower than the selected number, the application will alert the player. When the player guesses the number, the app will tell them and the program will exit. +2. The player tries to guess this number. The application prompts if the player to enter an integer. If the player enters letters or floats, the app asks them to correct it. If the entered number is higher or lower than the selected number, the application alerts the player. If the player guesses the number, the app will tell them and the game is ending. -If the player wants to quit the application during the game, he can use "CTRL+C". \ No newline at end of file +3. If the player wants to quit the application during the game, he can to use keyboard "CTRL+C". \ No newline at end of file diff --git a/1] guessing game/main.py b/1] guessing game/main.py index 428bc6f..6d8d07e 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -3,11 +3,11 @@ def num_guessing_game() -> int: """ - The function of guessing a random number between 1 and 100. - - The function using randint will generate a number, and using - while loop accepts number tips from the user. once - the user guesses the number, the program ends. + The function uses randint() and generates a number in + the range 1-100. Then it uses "while loop" and it gets + number tip from the player. The functions says the player + if is his tip higher or lower until the player guesses + the number. """ print("Welcome to our guessing game! " "Can you guess the number between 1 and 100?") diff --git a/2] loto/README.md b/2] loto/README.md new file mode 100644 index 0000000..3a3f55a --- /dev/null +++ b/2] loto/README.md @@ -0,0 +1,25 @@ +## LOTTO SIMULATOR + +Simple console LOTTO application. The application gives 6 random numbers in range 1 - 49 and player is guessing them. + + +# Lauched application + +Use the "cd" command to navigate to the "2] loto" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +1. The function gets the list numbers from a player and while checks: +- whether the entered text is a valid number, +- whether the user has not entered a given number before, +- if the number is in the range of 1-49. +2. The function uses randint (Random library) and gets a list of six original winning numbers in the range 1-49. +3. The function dislays list of numbers from player and list of winning numbers and then compares them. +4. The function displays how many numbers the player guessed. \ No newline at end of file diff --git a/2] loto/main.py b/2] loto/main.py index 4946943..598a635 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -3,11 +3,11 @@ def nums_of_player() -> list: """ - The function retrieves a list of six original numbers - from the player. + The function gets a list of six original numbers + of the player. Funktion checks whether: - player entered integer in range of 1-49, + player entered integer in the range 1-49, player has not entered a given number before. Funktion return a sorted list of numbers. @@ -34,8 +34,8 @@ def nums_of_player() -> list: def winning_nums() -> list: """ - The function uses randint (Random library) and gets a list - of six original numbers from the range 1-49. + The function uses randint() and gets a list + of six original numbers in the range 1-49. """ draw_nums = [] while len(draw_nums) < 6: @@ -46,10 +46,10 @@ def winning_nums() -> list: def main(): """ - The function uses the "nums_of_player()" function and gets the list - numbers from a player. Then uses the "winning_nums()" function and gets - list of drawn numbers. - The function dislays lists of numbers and compares them. Then + The function uses the "nums_of_player()" function and it gets the list + numbers from a player. Then it uses the "winning_nums()" function and + it gets list of winning numbers. + The function dislays these lists of numbers and compares them. Then it displays how many numbers the player guessed. """ print(f"WELCOME TO THE PYTHON LOTTERY!\n{'=' * 30}\nWe draw " diff --git a/3] guessing game 2/README.md b/3] guessing game 2/README.md index 0e52a35..3c33183 100644 --- a/3] guessing game 2/README.md +++ b/3] guessing game 2/README.md @@ -1,11 +1,11 @@ -## GUESSING GAME +## Number guessing game 2 -Symple console application LOTTO simulator. +A simple console application that guesses a player's number in the range of 1-1000. # Lauched application -Use the "cd" command to navigate to the "2] loto" folder and enter the command: +Use the "cd" command to navigate to the "3] guessing game 2" folder and enter the command: for LINUX python3 main.py @@ -16,10 +16,8 @@ for WINDOWS # Running application -1. The function gets the list numbers from a player and while checks: -- whether the string entered is a valid number, -- whether the user has not entered a given number before, -- if the number is in the range of 1-49. -2. The function uses randint (Random library) and gets a list of six original numbers from the range 1-49. -3. The function dislays list of numbers from player and list of winning numbers and then compares them. -4. The function displays how many numbers the player guessed. \ No newline at end of file +1. The function greets a player and uses a math formula for getting most likely numbers in the range 0 - 1000. + +2. Then the function finds, if is the number correct, too hight or too low. If the quessed number is not correct, the function change numbers for calculation and repeats the process. + +3. This process is repeat only ten times, because if is it not enought, the game is not fair. diff --git a/3] guessing game 2/main.py b/3] guessing game 2/main.py index e69de29..464b1e6 100644 --- a/3] guessing game 2/main.py +++ b/3] guessing game 2/main.py @@ -0,0 +1,62 @@ +def get_answer() -> str: + """ + A function for getting player's answer. + + A function gets the player's answer and chcek if + it is in the list of correct answers. If it is, it + return answer as string. If it is not, the function + starts again. + """ + # getting an answer + answer = input("(ALLOWED ANSWERS: too low / too high / " + "you quessed):\n") + + # answer check + correct_answers = ["too low", "too high", "you quessed"] + if answer in correct_answers: + return answer + else: + print("Wrong value, try again...") + get_answer() + + +def main(): + """ + A function for guessing a number. + + The function uses a math formula for getting most + likely numbers in the range 0 - 1000. Then the function + uses get_answer() for information, if is the number correct, + too hight or too low. + If the quessed number is not correct, the function change + numbers for calculation and repeats the process. + If the game is fair, the PC guesses the number within ten cycles. + """ + # hello area + print("Think about a number from 0 do 1000 and " + f"let me guess it!\n{'=' * 56}") + + min = 0 + max = 1000 + num_of_tries = 10 + + while num_of_tries: + # calculation of the quessed number + guess = int((max-min) / 2) + min + print(f"Guessing: {guess}. Am I right?") + print(f"Pokus {num_of_tries}") + + # processing the player's response + answer = get_answer() + if answer == "too high": + max = guess + num_of_tries -= 1 + elif answer == "too low": + min = guess + num_of_tries -= 1 + elif answer == "you quessed": + print("I won!") + num_of_tries = 0 + + +main() \ No newline at end of file diff --git a/4] guessing game 3/README.md b/4] guessing game 3/README.md new file mode 100644 index 0000000..193095a --- /dev/null +++ b/4] guessing game 3/README.md @@ -0,0 +1,23 @@ +## Number guessing game 2 + +A simple console application ... + + +# Lauched application + +Use the "cd" command to navigate to the "4] guessing game 3" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +1. ... + +2. ... + +3. ... diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index e69de29..470fa03 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -0,0 +1,31 @@ +from flask import Flask, request, render_template + +app = Flask(__name__) + +minimum = 0 +maximum = 1000 + + +@app.route("/", methods=["GET", "POST"]) +def game(): + if request.method == "GET": + return render_template("index.html") + elif request.method == "POST": + + # used_button = request.form("button") + # if used_button == "too_low": + # minimum = request.form["guess"] + + # elif used_button == "too_high": + # maximum == request.form["guess"] + + # elif used_button == "you_win": + # return render_template("i_win.html") + + guess = int((maximum-minimum) / 2) + minimum + return render_template("guessing.html", guess=guess) + + + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file diff --git a/4] guessing game 3/templates/guessing.html b/4] guessing game 3/templates/guessing.html new file mode 100644 index 0000000..7cba7da --- /dev/null +++ b/4] guessing game 3/templates/guessing.html @@ -0,0 +1,20 @@ + + + + + + Guessing GAME + + +

GUESSING GAME

+ +

I guess {{ guess }}, it is right?

+ +
+ + + +
+ + + \ No newline at end of file diff --git a/4] guessing game 3/templates/i_win.html b/4] guessing game 3/templates/i_win.html new file mode 100644 index 0000000..5c35edc --- /dev/null +++ b/4] guessing game 3/templates/i_win.html @@ -0,0 +1,19 @@ + + + + + + Guessing GAME + + +

Yeah! I WIN!

+ +

Thank you for a game! Do you want to play again? +

+ +
+ +
+ + + \ No newline at end of file diff --git a/4] guessing game 3/templates/index.html b/4] guessing game 3/templates/index.html new file mode 100644 index 0000000..2c37ad8 --- /dev/null +++ b/4] guessing game 3/templates/index.html @@ -0,0 +1,20 @@ + + + + + + Guessing GAME + + +

LET'S PLAY A GUESSING GAME!

+ +

PRAVIDLA: Mysli na číslo od 0 do 1000. Pak mi řekni, jestli jsem číslo + uhodnul nebo jestli je moje číslo příliš nízké nebo příliš vysoké. +

+ +
+ +
+ + + \ No newline at end of file diff --git a/5] 2001/README.md b/5] 2001/README.md new file mode 100644 index 0000000..6a7a776 --- /dev/null +++ b/5] 2001/README.md @@ -0,0 +1,23 @@ +## Number guessing game 2 + +A simple console application ... + + +# Lauched application + +Use the "cd" command to navigate to the "5] 2001" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +1. ... + +2. ... + +3. ... diff --git a/5] dice/README.md b/5] dice/README.md new file mode 100644 index 0000000..c545011 --- /dev/null +++ b/5] dice/README.md @@ -0,0 +1,23 @@ +## Number guessing game 2 + +A simple console application ... + + +# Lauched application + +Use the "cd" command to navigate to the "5] dice" folder and enter the command: + +for LINUX + python3 main.py + +for WINDOWS + python main.py + + +# Running application + +1. ... + +2. ... + +3. ... From b651e2d55957137b191747422e98d76812d53547 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Fri, 2 Feb 2024 16:04:58 +0100 Subject: [PATCH 05/15] =?UTF-8?q?oprava=20cvi=C4=8Den=C3=AD=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4] guessing game 3/main.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index 470fa03..1c2cef2 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -2,28 +2,34 @@ app = Flask(__name__) -minimum = 0 -maximum = 1000 +min_num = 0 +max_num = 1000 +used_button = "" + +@app.route("/geussing", methods=["GET", "POST"]) +def geussing(button=used_button): + return used_button == request.form("button") @app.route("/", methods=["GET", "POST"]) -def game(): +def game(minimum=min_num, maximum=max_num): if request.method == "GET": return render_template("index.html") elif request.method == "POST": - # used_button = request.form("button") - # if used_button == "too_low": - # minimum = request.form["guess"] - # elif used_button == "too_high": - # maximum == request.form["guess"] + if used_button == "too_low": + minimum = request.form["guess"] + + elif used_button == "too_high": + maximum == request.form["guess"] - # elif used_button == "you_win": - # return render_template("i_win.html") + elif used_button == "you_win": + return render_template("i_win.html") + else: - guess = int((maximum-minimum) / 2) + minimum - return render_template("guessing.html", guess=guess) + guess = int((maximum-minimum) / 2) + minimum + return render_template("guessing.html", guess=guess) From 89376fce16eb66721a95f58b543f4534f8389ef8 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Fri, 2 Feb 2024 20:00:26 +0100 Subject: [PATCH 06/15] =?UTF-8?q?oprava=20=C4=8Dtvrt=C3=A9ho=20cvi=C4=8Den?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4] guessing game 3/main.py | 50 ++++++++++++++-------- 4] guessing game 3/templates/guessing.html | 35 +++++++++++---- 4] guessing game 3/templates/i_win.html | 27 +++++++++--- 4] guessing game 3/templates/index.html | 32 ++++++++++---- 4 files changed, 103 insertions(+), 41 deletions(-) diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index 1c2cef2..626cada 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -4,33 +4,47 @@ min_num = 0 max_num = 1000 -used_button = "" +guess = 0 -@app.route("/geussing", methods=["GET", "POST"]) -def geussing(button=used_button): - return used_button == request.form("button") +def calculation(minimum=int, maximum=int) -> int: + return int((maximum-minimum) / 2) + minimum -@app.route("/", methods=["GET", "POST"]) -def game(minimum=min_num, maximum=max_num): - if request.method == "GET": - return render_template("index.html") - elif request.method == "POST": +@app.route("/too_low", methods=["GET", "POST"]) +def too_low(): + global min_num, max_num, guess + min_num = guess + guess = calculation(min_num, max_num) + return render_template("guessing.html", guess=guess) + +@app.route("/too_high", methods=["GET", "POST"]) +def too_high(): + global min_num, max_num, guess + max_num = guess + guess = calculation(min_num, max_num) + return render_template("guessing.html", guess=guess) - if used_button == "too_low": - minimum = request.form["guess"] - elif used_button == "too_high": - maximum == request.form["guess"] +@app.route("/you_win", methods=["GET", "POST"]) +def you_win(): + global min_num, max_num, guess + min_num = 0 + max_num = 1000 + guess = 0 - elif used_button == "you_win": - return render_template("i_win.html") - else: + return render_template("i_win.html") - guess = int((maximum-minimum) / 2) + minimum - return render_template("guessing.html", guess=guess) + +@app.route("/", methods=["GET", "POST"]) +def game(): + if request.method == "GET": + return render_template("index.html") + elif request.method == "POST": + global min_num, max_num, guess + guess = calculation(min_num, max_num) + return render_template("guessing.html", guess=guess) if __name__ == "__main__": diff --git a/4] guessing game 3/templates/guessing.html b/4] guessing game 3/templates/guessing.html index 7cba7da..2b3d3e5 100644 --- a/4] guessing game 3/templates/guessing.html +++ b/4] guessing game 3/templates/guessing.html @@ -4,17 +4,36 @@ Guessing GAME + -

GUESSING GAME

+
+

GUESSING GAME

-

I guess {{ guess }}, it is right?

+

I guess {{ guess }}, it is right?

-
- - - -
- +
+ +
+ +
+ +
+ +
+ +
+
\ No newline at end of file diff --git a/4] guessing game 3/templates/i_win.html b/4] guessing game 3/templates/i_win.html index 5c35edc..3ff7e76 100644 --- a/4] guessing game 3/templates/i_win.html +++ b/4] guessing game 3/templates/i_win.html @@ -4,16 +4,29 @@ Guessing GAME + -

Yeah! I WIN!

+
+

Yeah! I WIN!

-

Thank you for a game! Do you want to play again? -

+

Thank you for a game! Do you want to play again? +

-
- -
- +
+ +
+
\ No newline at end of file diff --git a/4] guessing game 3/templates/index.html b/4] guessing game 3/templates/index.html index 2c37ad8..84c07cb 100644 --- a/4] guessing game 3/templates/index.html +++ b/4] guessing game 3/templates/index.html @@ -4,17 +4,33 @@ Guessing GAME + -

LET'S PLAY A GUESSING GAME!

+
+

LET'S PLAY A GUESSING GAME!

-

PRAVIDLA: Mysli na číslo od 0 do 1000. Pak mi řekni, jestli jsem číslo - uhodnul nebo jestli je moje číslo příliš nízké nebo příliš vysoké. -

+

RULES: Think about a number in the range + 0 - 1000.
Then say me, if my guess is right, too + high or too low.

-
- -
- +
+ +
+
\ No newline at end of file From ce5e9423a3ae62d0c73097d3d39cfd03a8538d21 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 09:54:07 +0100 Subject: [PATCH 07/15] =?UTF-8?q?Oprava=20prvn=C3=ADho=20a=20druh=C3=A9ho?= =?UTF-8?q?=20cvi=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1] guessing game/main.py | 25 ++++++++++++++----------- 2] loto/main.py | 20 ++++++++------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/1] guessing game/main.py b/1] guessing game/main.py index 6d8d07e..cba70c1 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -1,7 +1,7 @@ from random import randint -def num_guessing_game() -> int: +def num_guessing_game(): """ The function uses randint() and generates a number in the range 1-100. Then it uses "while loop" and it gets @@ -20,19 +20,22 @@ def num_guessing_game() -> int: try: player_num = int(input("Enter whole number: ")) - # testing a player's number - if player_num < wanted_num: - print("Too small number...") - continue - elif player_num > wanted_num: - print("Too big number...") - continue - else: - return "!!! YOU WIN !!!" - # wrong value entery check except ValueError: print("You entered the wrong value, try again...") + continue + + # testing a player's number + if player_num < wanted_num: + print("Too small number...") + continue + elif player_num > wanted_num: + print("Too big number...") + continue + else: + return "!!! YOU WIN !!!" + + print(num_guessing_game()) diff --git a/2] loto/main.py b/2] loto/main.py index 598a635..71465a6 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -1,7 +1,7 @@ from random import randint -def nums_of_player() -> list: +def nums_of_player() -> set: """ The function gets a list of six original numbers of the player. @@ -13,7 +13,7 @@ def nums_of_player() -> list: Funktion return a sorted list of numbers. """ # gettint a list of numbers - player_nums = [] + player_nums = set() while len(player_nums)<6: try: num = int(input(f"Enter number No. {len(player_nums) +1}: ")) @@ -23,23 +23,22 @@ def nums_of_player() -> list: elif num < 1 or num > 49: print("The number is not in range of 1 - 49. Try again...") else: - player_nums.append(num) + player_nums.add(num) except ValueError: print("Value is not whole number. Try again...") - player_nums.sort() return player_nums -def winning_nums() -> list: +def winning_nums() -> set: """ The function uses randint() and gets a list of six original numbers in the range 1-49. """ - draw_nums = [] + draw_nums = set() while len(draw_nums) < 6: - draw_nums.append(randint(1, 50)) + draw_nums.add(randint(1, 50)) return draw_nums @@ -64,12 +63,9 @@ def main(): print(f"Winning numbers:\n{', '.join(map(str, draw_nums))}") # evaluation of results - hits = 0 - for num in player_nums: - if num in draw_nums: - hits += 1 + hits = draw_nums.intersection(player_nums) separator = "=" * 25 - print(f"{separator}\nSUM OF GUESSED NUMBERS: {hits}\n{separator}") + print(f"{separator}\nSUM OF GUESSED NUMBERS: {len(hits)}\n{separator}") main() From 9874229f97eb7c87aafbef7cebc5ca5dd050c40f Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 10:07:24 +0100 Subject: [PATCH 08/15] =?UTF-8?q?opraveno=20t=C5=99et=C3=AD=20cvi=C4=8Den?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3] guessing game 2/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3] guessing game 2/main.py b/3] guessing game 2/main.py index 464b1e6..dfc0e39 100644 --- a/3] guessing game 2/main.py +++ b/3] guessing game 2/main.py @@ -42,7 +42,7 @@ def main(): while num_of_tries: # calculation of the quessed number - guess = int((max-min) / 2) + min + guess = (max-min) // 2 + min print(f"Guessing: {guess}. Am I right?") print(f"Pokus {num_of_tries}") From bda1fa7fe02d6987b3057fb9af63df6e003403a1 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 10:13:26 +0100 Subject: [PATCH 09/15] =?UTF-8?q?oprava=20prvn=C3=ADho=20cvi=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1] guessing game/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/1] guessing game/main.py b/1] guessing game/main.py index cba70c1..cdd59ad 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -1,7 +1,7 @@ from random import randint -def num_guessing_game(): +def num_guessing_game() -> None: """ The function uses randint() and generates a number in the range 1-100. Then it uses "while loop" and it gets @@ -32,8 +32,9 @@ def num_guessing_game(): elif player_num > wanted_num: print("Too big number...") continue - else: - return "!!! YOU WIN !!!" + else: + print("!!! YOU WIN !!!") + return From 433d0dfd7554c1068d26f78002829f1b9f2f859a Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 12:59:56 +0100 Subject: [PATCH 10/15] =?UTF-8?q?vypracov=C3=A1no=20p=C3=A1t=C3=A9=20cvi?= =?UTF-8?q?=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4] guessing game 3/main.py | 2 +- 5] 2001/README.md | 12 ++-- 5] 2001/main.py | 128 +++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 5 deletions(-) diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index 626cada..b766be1 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -7,7 +7,7 @@ guess = 0 def calculation(minimum=int, maximum=int) -> int: - return int((maximum-minimum) / 2) + minimum + return (maximum-minimum) // 2 + minimum @app.route("/too_low", methods=["GET", "POST"]) diff --git a/5] 2001/README.md b/5] 2001/README.md index 6a7a776..41b285d 100644 --- a/5] 2001/README.md +++ b/5] 2001/README.md @@ -1,6 +1,10 @@ ## Number guessing game 2 -A simple console application ... +Aplikace pro výpočet hodu kostkou ve formátu xDy+z kde: +x = počet hodů kostkou (nepovinné) +D = sympol pro označení druhu kostky (povinné) +y = označení kolikastěnná je kostka (povinné) ++z = modifikátor, který označí matematickou operaci, která se má s výsledkem hodu provést - povoleno je +, -, *, / (nepovinné) # Lauched application @@ -16,8 +20,8 @@ for WINDOWS # Running application -1. ... +1. Fukce přijme argument ve formátu strint a pokusí se jej rozdělit podle D. -2. ... +2. Fukce se snaží vyhodnotit hodnotu před D a po D a kontroluje při tom, jestli uživatel zadal správnou hodnotu. -3. ... +3. Na základně zjištěních hodnot funkce vypočítá výsledek. diff --git a/5] 2001/main.py b/5] 2001/main.py index e69de29..bc0ed9f 100644 --- a/5] 2001/main.py +++ b/5] 2001/main.py @@ -0,0 +1,128 @@ +from random import randint + + +def calculation(x: int, y: int) -> int: + """ + Vnořená funkce obsahující základní vzorec + pro výpočet hodu kostkou bez modifikátoru. + """ + return x * (randint(1, y+1)) + + +def second_cut_check(first_cut_1: str, math_mark_str: int): + """ + Vnořená funkce pro vyhodnocení druhé části zadané + hodnoty, pokud byl použit modifikátor. + Pokud byla hodnota zadáná správně, funce vrátí tuple + obsahující druh kostky a modifikátor jako int. + Pokud byla hodnota zadána špatně, funkce vrátí None. + """ + second_cut = first_cut_1.split(math_mark_str) + if len(second_cut) != 2: + return + + try: + dice = int(second_cut[0]) + modifier = int(second_cut[1]) + return dice, modifier + except ValueError: + return + + +def dice_calculation(entered_value: str): + """ + Funkce pro vyhodnocení hodů kostkou, který uživatel zadá + ve formátu xDy+z kde: + x = roll (počet hodů) + y = dice (kolikastěnná je kostka) + z = modifier (hodnota pro mat. operaci, která se má + s výsledkem hodů provést) + + Fukce zkontroluje správnost zadané hodnoty a následně + pomocí funkce calculation() vypočítá a vrátí výsledek + ve formátu int. + Pokud bude hodnota zadána špatně, vrátí uživateli chybovou + hlášku. + """ + error_allert = "WRONG VALUE: a correct value is in format xDy+z." + roll = 0 + dice = 0 + modifier = 0 + math_mark = "" + + # first format check + if "D" not in entered_value: + return error_allert + + # first split + additional check + first_cut = entered_value.split("D") + if len(first_cut) != 2: + return error_allert + + if first_cut[1] == False: + return error_allert + + # getting value roll + if first_cut[0]: + try: + roll = int(first_cut[0]) + except ValueError: + return error_allert + else: + roll = 1 + + # getting value dice + if (first_cut[1]).isdigit(): + dice = int(first_cut[1]) + else: + #getting value modifier + if "+" in first_cut[1]: + math_mark = "+" + second_cut = second_cut_check(first_cut[1], math_mark) + if second_cut == None: + return error_allert + else: + dice = second_cut[0] + modifier = second_cut[1] + + elif "-" in first_cut[1]: + math_mark = "-" + second_cut = second_cut_check(first_cut[1], math_mark) + if second_cut == None: + return error_allert + else: + dice = second_cut[0] + modifier = second_cut[1] + + elif "*" in first_cut[1]: + math_mark = "*" + second_cut = second_cut_check(first_cut[1], math_mark) + if second_cut == None: + return error_allert + else: + dice = second_cut[0] + modifier = second_cut[1] + + elif "/" in first_cut[1]: + math_mark = "/" + second_cut = second_cut_check(first_cut[1], math_mark) + if second_cut == None: + return error_allert + else: + dice = second_cut[0] + modifier = second_cut[1] + + else: + return error_allert + + # calculation for rolls of a dice without a modifier + if not modifier: + return calculation(roll, dice) + + # calculation for rolls of a dice with a modifier + else: + return eval(str(calculation(roll, dice)) + math_mark + str(modifier)) + + + +print(dice_calculation("2D4+5+5")) \ No newline at end of file From 97bcbb66c4663fea50067b38e8e7322594374059 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 14:29:05 +0100 Subject: [PATCH 11/15] =?UTF-8?q?oprava=20p=C3=A1t=C3=A9ho=20cvi=C4=8Den?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5] 2001/README.md | 6 +- 5] 2001/main.py | 147 ++++++++++++++-------------------------------- 2 files changed, 47 insertions(+), 106 deletions(-) diff --git a/5] 2001/README.md b/5] 2001/README.md index 41b285d..a2a1c89 100644 --- a/5] 2001/README.md +++ b/5] 2001/README.md @@ -20,8 +20,8 @@ for WINDOWS # Running application -1. Fukce přijme argument ve formátu strint a pokusí se jej rozdělit podle D. +1. Fukce přijme argument ve formátu strint a zkontroluje, zda byla použita správná kostka. Pokud ne, vrátí chybové hlášení. -2. Fukce se snaží vyhodnotit hodnotu před D a po D a kontroluje při tom, jestli uživatel zadal správnou hodnotu. +2. Pokud ano, funkce se pokusí získat i další hodnoty. Kontroluje, zda byly zadány správně a pokud ne, vrátí chybové hlášení. -3. Na základně zjištěních hodnot funkce vypočítá výsledek. +3. Na základně zjištěních hodnot funkce vypočítá výsledek a vrátí ho ve formě int. diff --git a/5] 2001/main.py b/5] 2001/main.py index bc0ed9f..13c6731 100644 --- a/5] 2001/main.py +++ b/5] 2001/main.py @@ -9,120 +9,61 @@ def calculation(x: int, y: int) -> int: return x * (randint(1, y+1)) -def second_cut_check(first_cut_1: str, math_mark_str: int): - """ - Vnořená funkce pro vyhodnocení druhé části zadané - hodnoty, pokud byl použit modifikátor. - Pokud byla hodnota zadáná správně, funce vrátí tuple - obsahující druh kostky a modifikátor jako int. - Pokud byla hodnota zadána špatně, funkce vrátí None. - """ - second_cut = first_cut_1.split(math_mark_str) - if len(second_cut) != 2: - return - - try: - dice = int(second_cut[0]) - modifier = int(second_cut[1]) - return dice, modifier - except ValueError: - return - - def dice_calculation(entered_value: str): """ - Funkce pro vyhodnocení hodů kostkou, který uživatel zadá - ve formátu xDy+z kde: - x = roll (počet hodů) - y = dice (kolikastěnná je kostka) - z = modifier (hodnota pro mat. operaci, která se má - s výsledkem hodů provést) - - Fukce zkontroluje správnost zadané hodnoty a následně - pomocí funkce calculation() vypočítá a vrátí výsledek - ve formátu int. - Pokud bude hodnota zadána špatně, vrátí uživateli chybovou - hlášku. + Funkce pro výpočet hodu kostkou. Funkce zkontroluje + jestli byla zadána povolená kostka a správné hodnoty. + Pokud ano, vrátí hodnotu hodu za použití funkce + calculation(). Pokud ne, vrátí chybové hlášení. """ - error_allert = "WRONG VALUE: a correct value is in format xDy+z." - roll = 0 + error_dice = "WRONG DICE: a correct dice - D3, D4, D6, D8, D10, D12, D20, D100" + error_value = "WRONG VALUE: a correct value is in format xDy+z." + correct_dice = ("D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100") + + rolls = 0 dice = 0 modifier = 0 math_mark = "" - # first format check - if "D" not in entered_value: - return error_allert - - # first split + additional check - first_cut = entered_value.split("D") - if len(first_cut) != 2: - return error_allert + # získání typu kostky + kontrola + for correct_dice in correct_dice: + if correct_dice in entered_value: + dice = int(correct_dice.strip("D")) + first_cut = entered_value.split(correct_dice) + break + if dice == 0: + return error_dice - if first_cut[1] == False: - return error_allert - - # getting value roll + # získání počtu hodů + kontrola if first_cut[0]: try: - roll = int(first_cut[0]) + rolls = int(first_cut[0]) except ValueError: - return error_allert + return error_value else: - roll = 1 - - # getting value dice - if (first_cut[1]).isdigit(): - dice = int(first_cut[1]) + rolls = 1 + + # získání případného modifikátoru + kontrola + if first_cut[1]: + correct_mark = ("+", "-", "*", "/") + for mark in correct_mark: + if mark in first_cut[1]: + math_mark = mark + try: + modifier = int(first_cut[1].strip(mark)) + break + except: + return error_value + if not math_mark: + return error_value + + # výpočet hodu s modifikátorem + if modifier: + return eval(str(calculation(rolls, dice)) + math_mark + str(modifier)) + + # výpočet hodu bez modifikátoru else: - #getting value modifier - if "+" in first_cut[1]: - math_mark = "+" - second_cut = second_cut_check(first_cut[1], math_mark) - if second_cut == None: - return error_allert - else: - dice = second_cut[0] - modifier = second_cut[1] - - elif "-" in first_cut[1]: - math_mark = "-" - second_cut = second_cut_check(first_cut[1], math_mark) - if second_cut == None: - return error_allert - else: - dice = second_cut[0] - modifier = second_cut[1] - - elif "*" in first_cut[1]: - math_mark = "*" - second_cut = second_cut_check(first_cut[1], math_mark) - if second_cut == None: - return error_allert - else: - dice = second_cut[0] - modifier = second_cut[1] - - elif "/" in first_cut[1]: - math_mark = "/" - second_cut = second_cut_check(first_cut[1], math_mark) - if second_cut == None: - return error_allert - else: - dice = second_cut[0] - modifier = second_cut[1] - - else: - return error_allert - - # calculation for rolls of a dice without a modifier - if not modifier: - return calculation(roll, dice) - - # calculation for rolls of a dice with a modifier - else: - return eval(str(calculation(roll, dice)) + math_mark + str(modifier)) - - + return calculation(rolls, dice) + -print(dice_calculation("2D4+5+5")) \ No newline at end of file +print(dice_calculation("2D10+5")) \ No newline at end of file From fae5946cd66dffe4f2751d9c25690e4b4ba297fb Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 14:43:56 +0100 Subject: [PATCH 12/15] =?UTF-8?q?snad=20u=C5=BE=20posledn=C3=AD=20oprava?= =?UTF-8?q?=20p=C3=A1t=C3=A9ho=20cvi=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5] 2001/README.md | 2 +- 5] 2001/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/5] 2001/README.md b/5] 2001/README.md index a2a1c89..5fcda55 100644 --- a/5] 2001/README.md +++ b/5] 2001/README.md @@ -4,7 +4,7 @@ Aplikace pro výpočet hodu kostkou ve formátu xDy+z kde: x = počet hodů kostkou (nepovinné) D = sympol pro označení druhu kostky (povinné) y = označení kolikastěnná je kostka (povinné) -+z = modifikátor, který označí matematickou operaci, která se má s výsledkem hodu provést - povoleno je +, -, *, / (nepovinné) ++z = modifikátor, který označí matematickou operaci, která se má s výsledkem hodu provést - povoleno je +, - (nepovinné) # Lauched application diff --git a/5] 2001/main.py b/5] 2001/main.py index 13c6731..fb7107a 100644 --- a/5] 2001/main.py +++ b/5] 2001/main.py @@ -45,7 +45,7 @@ def dice_calculation(entered_value: str): # získání případného modifikátoru + kontrola if first_cut[1]: - correct_mark = ("+", "-", "*", "/") + correct_mark = ("+", "-") for mark in correct_mark: if mark in first_cut[1]: math_mark = mark From fce33c582d4472f6dc48a69da7b58b482481ba29 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 19:26:37 +0100 Subject: [PATCH 13/15] =?UTF-8?q?vypracov=C3=A1no=20=C4=8Dtvrt=C3=A9=20cvi?= =?UTF-8?q?=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4] guessing game 3/README.md | 10 +-- 4] guessing game 3/main.py | 73 ++++++++++++---------- 4] guessing game 3/templates/guessing.html | 15 +++-- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/4] guessing game 3/README.md b/4] guessing game 3/README.md index 193095a..85da2e5 100644 --- a/4] guessing game 3/README.md +++ b/4] guessing game 3/README.md @@ -1,6 +1,6 @@ ## Number guessing game 2 -A simple console application ... +Flasková aplikace, ve které PC hádá číslo v rozsahu 0-1000. # Lauched application @@ -16,8 +16,10 @@ for WINDOWS # Running application -1. ... +1. Aplikace uvítá hráče a zeptá se ho, jestli chce hrát. -2. ... +2. Po potvrzení se zobrazí hrací stránka s tipem čísla od počítače a hráč je vyzván, aby řekl, jestli je číslo moc vysoké nebo nízké nebo jestli je to správné číslo. -3. ... +3. Po kliknutí na tlačítko "too low" nebo "too hide" se tip čísla přepočítá a znovu se opakuje bod dva. + +4. Pokud je tipované číslo správné, hráč klikne na tlačítko "you win". PC poděkuje za hru a dá hráči možnost zahrát si zvovu. diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index b766be1..868dd73 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -2,49 +2,58 @@ app = Flask(__name__) -min_num = 0 -max_num = 1000 -guess = 0 def calculation(minimum=int, maximum=int) -> int: + """ + Fukce se základním vzorcem pro výpočet + tipu čísla. + """ return (maximum-minimum) // 2 + minimum -@app.route("/too_low", methods=["GET", "POST"]) -def too_low(): - global min_num, max_num, guess - min_num = guess - guess = calculation(min_num, max_num) - return render_template("guessing.html", guess=guess) - - -@app.route("/too_high", methods=["GET", "POST"]) -def too_high(): - global min_num, max_num, guess - max_num = guess - guess = calculation(min_num, max_num) - return render_template("guessing.html", guess=guess) - - -@app.route("/you_win", methods=["GET", "POST"]) -def you_win(): - global min_num, max_num, guess - min_num = 0 - max_num = 1000 - guess = 0 - - return render_template("i_win.html") - - @app.route("/", methods=["GET", "POST"]) def game(): + """ + Aplikace pro hádání čísla hráče v rozsahu 0-1000. + Funkce získá vstupní hodnoty min a max, díky kterým + vypočítává nejpravděpodobnější číslo. Hodnoty jsou na + začátku nastavené defaltně a v průběhu hry se upravují + podle reakce uživatele dokud aplikace nedopočítá správné + číslo. + """ + # zobrazení úvodní stránky hry if request.method == "GET": return render_template("index.html") + + # zobrazení hrací stránky elif request.method == "POST": - global min_num, max_num, guess + # získání hodnot min/max/guess + min = int(request.form.get("min", default=0)) + max = int(request.form.get("max", default=1000)) + guess = 0 + + # úprava hodnot podle vstupu uživatele + answer = request.form.get("button") + if answer == "low": + min = int(request.form.get("guess")) + print(min, max) + guess = calculation(min, max) + return render_template("guessing.html", guess=guess, min=min, max=max) + + elif answer == "high": + max = int(request.form.get("guess")) + print(min, max) + guess = calculation(min, max) + return render_template("guessing.html", guess=guess, min=min, max=max) + + # zobrazení výherní stránky + elif answer == "win": + return render_template("i_win.html") - guess = calculation(min_num, max_num) - return render_template("guessing.html", guess=guess) + # první zobrazení hrací stránky (bez vstupu uživatele) + else: + guess = calculation(min, max) + return render_template("guessing.html", guess=guess, min=min, max=max) if __name__ == "__main__": diff --git a/4] guessing game 3/templates/guessing.html b/4] guessing game 3/templates/guessing.html index 2b3d3e5..cb68ac1 100644 --- a/4] guessing game 3/templates/guessing.html +++ b/4] guessing game 3/templates/guessing.html @@ -23,16 +23,15 @@

GUESSING GAME

I guess {{ guess }}, it is right?

-
- + + + + + + +
-
- -
- -
-
From 746f445b8e677f9b0c124efd05a01497fd5f79b2 Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Sat, 3 Feb 2024 19:59:16 +0100 Subject: [PATCH 14/15] =?UTF-8?q?oprava=20prom=C4=9Bnn=C3=BDch=20ve=20?= =?UTF-8?q?=C4=8Dtvrt=C3=A9m=20cvi=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4] guessing game 3/main.py | 32 +++++++++++----------- 4] guessing game 3/templates/guessing.html | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index 868dd73..4f17bb6 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -3,19 +3,19 @@ app = Flask(__name__) -def calculation(minimum=int, maximum=int) -> int: +def calculation(mnimum=int, mximum=int) -> int: """ Fukce se základním vzorcem pro výpočet tipu čísla. """ - return (maximum-minimum) // 2 + minimum + return (mximum-mnimum) // 2 + mnimum @app.route("/", methods=["GET", "POST"]) def game(): """ Aplikace pro hádání čísla hráče v rozsahu 0-1000. - Funkce získá vstupní hodnoty min a max, díky kterým + Funkce získá vstupní hodnoty mn a mx, díky kterým vypočítává nejpravděpodobnější číslo. Hodnoty jsou na začátku nastavené defaltně a v průběhu hry se upravují podle reakce uživatele dokud aplikace nedopočítá správné @@ -27,24 +27,24 @@ def game(): # zobrazení hrací stránky elif request.method == "POST": - # získání hodnot min/max/guess - min = int(request.form.get("min", default=0)) - max = int(request.form.get("max", default=1000)) + # získání hodnot mn/mx/guess + mn = int(request.form.get("mn", default=0)) + mx = int(request.form.get("mx", default=1000)) guess = 0 # úprava hodnot podle vstupu uživatele answer = request.form.get("button") if answer == "low": - min = int(request.form.get("guess")) - print(min, max) - guess = calculation(min, max) - return render_template("guessing.html", guess=guess, min=min, max=max) + mn = int(request.form.get("guess")) + print(mn, mx) + guess = calculation(mn, mx) + return render_template("guessing.html", guess=guess, mn=mn, mx=mx) elif answer == "high": - max = int(request.form.get("guess")) - print(min, max) - guess = calculation(min, max) - return render_template("guessing.html", guess=guess, min=min, max=max) + mx = int(request.form.get("guess")) + print(mn, mx) + guess = calculation(mn, mx) + return render_template("guessing.html", guess=guess, mn=mn, mx=mx) # zobrazení výherní stránky elif answer == "win": @@ -52,8 +52,8 @@ def game(): # první zobrazení hrací stránky (bez vstupu uživatele) else: - guess = calculation(min, max) - return render_template("guessing.html", guess=guess, min=min, max=max) + guess = calculation(mn, mx) + return render_template("guessing.html", guess=guess, mn=mn, mx=mx) if __name__ == "__main__": diff --git a/4] guessing game 3/templates/guessing.html b/4] guessing game 3/templates/guessing.html index cb68ac1..3bc97a6 100644 --- a/4] guessing game 3/templates/guessing.html +++ b/4] guessing game 3/templates/guessing.html @@ -28,8 +28,8 @@

I guess {{ guess }}, it is right?

- - + + From 89adde17b7c021118b8ccbabaacca3fadffc82ae Mon Sep 17 00:00:00 2001 From: Diana Prusova Date: Tue, 6 Feb 2024 09:32:05 +0100 Subject: [PATCH 15/15] =?UTF-8?q?P=C5=99id=C3=A1na=20mock=20exam.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock_exam/task_1.py | 15 +++++++++++ mock_exam/task_2.py | 24 +++++++++++++++++ mock_exam/task_3.py | 29 ++++++++++++++++++++ mock_exam/task_4.py | 11 ++++++++ mock_exam/task_5.py | 14 ++++++++++ mock_exam/task_6/task_6.py | 38 +++++++++++++++++++++++++++ mock_exam/task_6/templates/index.html | 26 ++++++++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 mock_exam/task_1.py create mode 100644 mock_exam/task_2.py create mode 100644 mock_exam/task_3.py create mode 100644 mock_exam/task_4.py create mode 100644 mock_exam/task_5.py create mode 100644 mock_exam/task_6/task_6.py create mode 100644 mock_exam/task_6/templates/index.html diff --git a/mock_exam/task_1.py b/mock_exam/task_1.py new file mode 100644 index 0000000..22f540d --- /dev/null +++ b/mock_exam/task_1.py @@ -0,0 +1,15 @@ +def shorten(entered_str: str) -> str: + """ + Funkce přijme libovolně dlouhý řetězec a vrátí + řetězec obsahující první písmeno každého slova + ze zadného stringu. + """ + cut_str = entered_str.split() + short_str = list(word[0].upper() for word in cut_str) + + return "".join(short_str) + + +print(shorten("Don't repeat yourself")) +print(shorten("Read the fine manual")) +print(shorten("All terrain armoured transport")) diff --git a/mock_exam/task_2.py b/mock_exam/task_2.py new file mode 100644 index 0000000..2e3d18c --- /dev/null +++ b/mock_exam/task_2.py @@ -0,0 +1,24 @@ +def singulars_and_plurals(word_list: list) -> dict: + """ + Funkce přijme list slov, rozdělí je na jednotná + a množná a vráti slovník, který obsahuje seznamy + těchto slov. + """ + shorted_words = {"singulars": [], "plurals": []} + for word in word_list: + if word[-1] != "s": + shorted_words["singulars"].append(word) + else: + shorted_words["plurals"].append(word) + + return shorted_words + + +test_list = [ + "tomato", "tomatoes", + "potato", "potatoes", + "cars", "unicorns", + "horse", "cow" +] + +print(singulars_and_plurals(test_list)) diff --git a/mock_exam/task_3.py b/mock_exam/task_3.py new file mode 100644 index 0000000..3aa99b0 --- /dev/null +++ b/mock_exam/task_3.py @@ -0,0 +1,29 @@ +def check_palindrome(entered_str: str) -> bool: + """ + Funkce přijme řetězec a očistí ho o mezery a speciální + znaky a zkontroluje, jestli se jedná o palindrom. + """ + ## VERZE, KDE SE NEZOHLEĎNUJÍ ZNAMÉNKA VE VĚTÁCH + # cls_string = (entered_str.lower()).replace(" ", "") + # if cls_string == cls_string[::-1]: + # return True + # else: + # return False + + illegal_char = (" ", ",", ";", ".", "!", "?") + entered_str = entered_str.lower() + + for char in illegal_char: + if char in entered_str: + entered_str = entered_str.replace(char, "") + + if entered_str == entered_str[::-1]: + return True + else: + return False + + +print(check_palindrome("racecar")) +print(check_palindrome("level")) +print(check_palindrome("Was it a car or a cat I saw?")) +print(check_palindrome("return")) \ No newline at end of file diff --git a/mock_exam/task_4.py b/mock_exam/task_4.py new file mode 100644 index 0000000..1ac495f --- /dev/null +++ b/mock_exam/task_4.py @@ -0,0 +1,11 @@ +def div(num1: int, num2: int) -> list: + """ + Funkce přijme dvě čísla jako začátek a konec řady + a vrátí seznam těchto čísel, kterou jsou dělitelná + dvěma, ale ne třema. + """ + num_list = list(num for num in range(num1, num2 + 1) if num % 2 == 0 and num % 3 != 0) + return num_list + +print(div(0, 20)) + \ No newline at end of file diff --git a/mock_exam/task_5.py b/mock_exam/task_5.py new file mode 100644 index 0000000..f3ed78d --- /dev/null +++ b/mock_exam/task_5.py @@ -0,0 +1,14 @@ +from random import randint + + +def roll(throw, dice=6, modifier=0): + """ + Funkce přijímá jeden povinný argument (throw) a dva volitelné + argumenty. Vypočítá hodnotu jednotlivých hodů, sečte a + případně připočítá modifikátor a vrátí výsledek. + """ + throw_list = list(randint(1, dice+1) for _ in range(throw)) + return sum(throw_list) + modifier + + +print(roll(5, 7, 2)) \ No newline at end of file diff --git a/mock_exam/task_6/task_6.py b/mock_exam/task_6/task_6.py new file mode 100644 index 0000000..1e2e1c5 --- /dev/null +++ b/mock_exam/task_6/task_6.py @@ -0,0 +1,38 @@ +from flask import Flask, request, render_template + +app = Flask(__name__) + +@app.route("/movies", methods=["GET", "POST"]) +def movies(): + """ + Aplikace umožní uživateli zadat název filmu a následně + prohledá uložený seznam a zobrazí uživateli informaci, + jestli film patří mezi oblíbené či nikoliv. + """ + movies = { + "favourite": ["A New Hope", "Empire Strikes Back", "Return of the Jedi", + "The Force Awakens", "Jaws", "Predator", "Mad Max", + "Back to the Future", "2001: A Space Odyssey", "Robocop", + "The Hitchhiker's Guide to the Galaxy", "Doctor Who", + "Aliens", "Alien", "Terminator", "Blade Runner", "Matrix"], + + "hated": ["The Phantom Menace", "Attack of the Clones", "Star Trek", + "Alien Resurrection", "Twilight"] + + } + if request.method == "POST": + ask_movie = request.form["name_movie"] + if ask_movie in movies["favourite"]: + answer = "The movie is FAVOURITE!" + elif ask_movie in movies["hated"]: + answer = "The movie is HATED!" + else: + answer = "No such movie." + + return render_template("index.html", answer=answer) + else: + return render_template("index.html") + + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file diff --git a/mock_exam/task_6/templates/index.html b/mock_exam/task_6/templates/index.html new file mode 100644 index 0000000..0455487 --- /dev/null +++ b/mock_exam/task_6/templates/index.html @@ -0,0 +1,26 @@ + + + + + + Movies + + + +
+

MOVIE ANALYZER

+
+ + +
+ +

{{ answer }}

+
+ + \ No newline at end of file