diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9de2865 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fc4741d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workshop.iml b/.idea/workshop.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/workshop.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/1] guessing game/main.py b/1] guessing game/main.py index e69de29..e28e0c9 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -0,0 +1,17 @@ +from random import randint +number = randint(1, 100) +win = False +while win == False: + #system generates a number in range 1-100 and user tries to guess it + #system provides clues Too small/too big and validates whether input is a number + try: + user_input = int(input("Guess a number between 1 and 100: ")) + if user_input < number: + print("Too small") + elif user_input > number: + print("Too big") + else: + print("You win!") + win = True + except ValueError: + print("It's not a number!") \ No newline at end of file diff --git a/2] loto/main.py b/2] loto/main.py index e69de29..ad347f6 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -0,0 +1,35 @@ +from random import randint + +user_input=[] +drawn_numbers=[] +matched=0 +#system collects 6 different numbers in given range and sorts them +for x in range(6): + while True: + try: + number = int(input(f"Input {x+1}. number in range 1-49: ")) + if number not in user_input and number in range(1,49): + user_input.append(number) + break + else: + print("Every number can be picked just once and must be in given range!") + except ValueError: + print("Input is not a number") +user_input.sort() +print(user_input) + +#system draws 6 random numbers and sorts them +for x in range(6): + while True: + number = randint(1,49) + if number not in drawn_numbers: + drawn_numbers.append(number) + break +drawn_numbers.sort() +print(drawn_numbers) + +#system checks whether there are some matches in user input and system draws +for x in range(6): + if user_input[x] in drawn_numbers: + matched +=1 +print(f'You matched {matched} number(s)') \ No newline at end of file diff --git a/3] guessing game 2/main.py b/3] guessing game 2/main.py index e69de29..900a370 100644 --- a/3] guessing game 2/main.py +++ b/3] guessing game 2/main.py @@ -0,0 +1,30 @@ +print("Think about a number from 0 to 1000 and let me guess it!") + +answer = "" +min = 0 +max = 1000 +count = 0 + +#the cycle continues till the guess is correct +while answer != "3": + + guess = int((max - min) / 2) + min + + #If the count of guesses reaches 10, user must be cheating, therefore system calls him liar + #Otherwise system cointinues guessing + if count == 10: + print("Liar liar pants on fire!") + break + else: + print(f"Guessing: {guess}") + count += 1 + + #user inputs a number to give a clue to the system + answer = input("Your verdict 1 - Too small, 2 - Too big, 3 - You win => ") + + if answer == "3": + print("I won! Thanks for game") + elif answer == "2": + max = guess + else: + min = guess diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index e69de29..71b849b 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -0,0 +1,36 @@ +from flask import Flask, render_template, request + +app = Flask(__name__, template_folder='templates') + +@app.route('/', methods=['GET', 'POST']) +def guess_number(): + min_num = 0 + max_num = 1000 + count = 0 + + #Flask post method that handles flow of values + if request.method == 'POST': + min_num = int(request.form.get('min')) + max_num = int(request.form.get('max')) + count = int(request.form.get('count')) + answer = request.form['answer'] + count += 1 + + # If the count of guesses reaches 10, user must be cheating, therefore system calls him liar + if count == 10: + return "Liar liar pants on fire!" + + if answer == "3": + return "I won! Thanks for game" + elif answer == "2": + max_num = int((max_num - min_num) / 2) + min_num + else: + min_num = int((max_num - min_num) / 2) + min_num + #counting number to guess + guess = int((max_num - min_num) / 2) + min_num + + #template and variable handling + return render_template('guess.html', min=min_num, max=max_num, count=count, guess=guess) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/4] guessing game 3/templates/guess.html b/4] guessing game 3/templates/guess.html new file mode 100644 index 0000000..e9b95d7 --- /dev/null +++ b/4] guessing game 3/templates/guess.html @@ -0,0 +1,33 @@ + + + + + Number Guessing Game + + +

Number Guessing Game

+

Think about a number from 0 to 1000 and let me guess it!

+

Guessing: {{ guess }}

+
+ + + + + +
+
+ + + + + +
+
+ + + + + +
+ + \ No newline at end of file diff --git a/5] dice/main.py b/5] dice/main.py index e69de29..ca9cf64 100644 --- a/5] dice/main.py +++ b/5] dice/main.py @@ -0,0 +1,22 @@ +import re +import random +#using regex and random to simulate the dice throw +def roll_dice(dice_code): + pattern = r'(\d*)D(\d+)([-+]\d+)?' + match = re.match(pattern, dice_code) + + try: + num_rolls = int(match.group(1)) if match.group(1) else 1 + dice_type = int(match.group(2)) + modifier = int(match.group(3)) if match.group(3) else 0 + result = sum(random.randint(1, dice_type) for _ in range(num_rolls)) + modifier + return result + except AttributeError: + return "Invalid dice" + + +print(roll_dice("2D10+10")) +print(roll_dice("D6")) +print(roll_dice("2D3")) +print(roll_dice("D12-1")) +print(roll_dice("XD1"))