diff --git a/1] guessing game/main.py b/1] guessing game/main.py index e69de29..ae3f03d 100644 --- a/1] guessing game/main.py +++ b/1] guessing game/main.py @@ -0,0 +1,25 @@ +### Game ### +import random + +def game(): + """ + Number guessing game from range 1-100 + """ + pc = random.randint(1,100) + while True: + try: + user = int(input("Guess the number: ")) + if user < pc: + print("Too small!") + continue + elif user > pc: + print("Too big!") + continue + else: + print("You win!") + break + except: + print("It's not a number!") + +if __name__ == '__main__': + game() \ No newline at end of file diff --git a/2] loto/main.py b/2] loto/main.py index e69de29..bef4007 100644 --- a/2] loto/main.py +++ b/2] loto/main.py @@ -0,0 +1,55 @@ +from random import shuffle + +def user_turn(): + user_list = [] + x = 0 + while x < 6: + try: + user = int(input("Choose a number: ")) + if user <= 49 and user not in user_list: + user_list.append(user) + x += 1 + else: + print("you have duplicity number or bigger that 49") + return None + except: + print("You must write numbers!") + return None + user_list.sort() + return user_list + + +def turn_parse(list): + return ', '.join(map(str, list)) + + +def pc_turn(): + pc_list = list(range(1,49)) + shuffle(pc_list) + return sorted(pc_list[:6]) + +def hit(a,b): + intersection_set = set(a) & set(b) + return("You hit", len(intersection_set), "number!.") + + +def lotto(): + user = user_turn() + if user is None: + return + pc = pc_turn() + + print("Your numbers: ") + parse_user = turn_parse(user) + print(parse_user) + + print("Lotto numers: ") + parse_pc = turn_parse(pc) + print(parse_pc) + + result = hit(user,pc) + print(result) + + +lotto() + diff --git a/3] guessing game 2/main.py b/3] guessing game 2/main.py index e69de29..4df613b 100644 --- a/3] guessing game 2/main.py +++ b/3] guessing game 2/main.py @@ -0,0 +1,32 @@ + +print("Image a number between 0 and 1000!") +input("Press 'Enter' to continue \n") + + +min = 0 +max = 1000 + +x = 0 +while x < 10: + x += 1 + + answer = ["low","high","win"] + guess = int((max-min) // 2 ) + min + print(f"Your number: {guess}") + user = input() + + + if x == 10: + print("Don't cheat!") + if user in answer: + if user == "low": + min = guess + elif user == "high": + max = guess + elif user == "win": + print("You won!") + break + else: + print(f"Only allow: {', '.join(answer)}") + x -= 1 + diff --git a/4] guessing game 3/main.py b/4] guessing game 3/main.py index e69de29..9561a7e 100644 --- a/4] guessing game 3/main.py +++ b/4] guessing game 3/main.py @@ -0,0 +1,27 @@ +from flask import Flask, render_template, request + +app = Flask(__name__) + +min_value = 0 +max_value = 1000 +guess = 500 + +@app.route("/", methods=["GET", "POST"]) +def index(): + global min_value, max_value, guess + if request.method == "POST": + + if "too_small" in request.form: + min_value = guess + elif "too_big" in request.form: + max_value = guess + else: + return render_template("win.html", min_value=min_value, max_value=max_value, guess=guess) + + guess = int((max_value - min_value) // 2 ) + min_value + return render_template("index.html", min_value=min_value, max_value=max_value, guess=guess) + +if __name__ == "__main__": + app.run(debug=True) + + diff --git a/4] guessing game 3/templates/index.html b/4] guessing game 3/templates/index.html new file mode 100644 index 0000000..6c0a792 --- /dev/null +++ b/4] guessing game 3/templates/index.html @@ -0,0 +1,18 @@ + + + + + + Guessing game + + +
+ + +

It is? {{ guess }}

+ + + +
+ + \ No newline at end of file diff --git a/4] guessing game 3/templates/win.html b/4] guessing game 3/templates/win.html new file mode 100644 index 0000000..f944846 --- /dev/null +++ b/4] guessing game 3/templates/win.html @@ -0,0 +1,13 @@ + + + + + + + Win + + + +

You win! Your number is {{ guess }}

+ + \ No newline at end of file diff --git a/5] dice/main.py b/5] dice/main.py index e69de29..d628ef3 100644 --- a/5] dice/main.py +++ b/5] dice/main.py @@ -0,0 +1,44 @@ +import re +import random +import sys + +allow_rols = {"3", "4", "6", "8", "10", "12", "20", "100"} + +def parser(dice): + return re.split(r'(\D+)', dice) + + +def roll_the_dice(roll): + parts = parser(roll) + + if parts[0]: + dice_roll = int(parts[0]) + else: + dice_roll = 1 + + if parts[1] != "D": + print("Invalid dice Type") + sys.exit() + + if parts[2] not in allow_rols: + print(f"Only allow dice type is: {','.join(allow_rols)}") + sys.exit() + + dice_type = int(parts[2]) + total = 0 + + for i in range(int(dice_roll)): + result = (random.randint(1,int(dice_type))) + total += result + + if len(parts) >= 5: + operation = parts[3] + operation_number = int(parts[4]) + if operation == "+": + total += int(operation_number) + elif operation == "-": + total -= int(operation_number) + + return total + +print(roll_the_dice("2D6+1")) \ No newline at end of file