Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 1] guessing game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Game ###
import random

def game():
"""
Number guessing game from range 1-100
"""
pc = random.randint(1,100)
while True:
try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ten try je lepsi udelt mensi a obalit jen tu cast, kde cekas ten error

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()
55 changes: 55 additions & 0 deletions 2] loto/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from random import shuffle

def user_turn():
user_list = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pouzij set

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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taky by bylo lepsi set


def hit(a,b):
intersection_set = set(a) & set(b)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protoze kdyzbys mel dva sety je tady z tech list nemusis zbytecne delat

return("You hit", len(intersection_set), "number!.")


def lotto():
user = user_turn()
if user is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc by mel byt user 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()

32 changes: 32 additions & 0 deletions 3] guessing game 2/main.py
Original file line number Diff line number Diff line change
@@ -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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle je lepsi udelat pres negtivni podminku abyses zbytecne nezanoroval

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

27 changes: 27 additions & 0 deletions 4] guessing game 3/main.py
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

globalni prommene nejsou dobra praxe. To se neuc pouzivat. To je hack. Neni to potreba, nainicializuj si je normalne uvnitr

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)


18 changes: 18 additions & 0 deletions 4] guessing game 3/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guessing game</title>
</head>
<body>
<form action="/" method="POST">
<input type="hidden" name="min" value="{{ min_value }}">
<input type="hidden" name="max" value="{{ max_value }}">
<p><h1> It is? {{ guess }} </h1></p>
<button type="submit" name="too_small">Too small</button>
<button type="submit" name="too_big">Too big</button>
<button type="submit" name="win">You Win!</button>
</form>
</body>
</html>
13 changes: 13 additions & 0 deletions 4] guessing game 3/templates/win.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Win</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<h1>You win! Your number is {{ guess }}</h1>
</body>
</html>
44 changes: 44 additions & 0 deletions 5] dice/main.py
Original file line number Diff line number Diff line change
@@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uf sys.exit asi ne e. proc ne proste return? nebo vyhod vyjimku kterou jste se ucili


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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mas tu celkem komplikovanou logiku celeho toho parsovani a neni to ani spravne. Umozni to zadat nesmysl jako kupr toto roll_the_dice("2D6-1QQQQQQQQ") coz by ten od mel zachytit jako chybny vstup.

To parsovani se typicky dela pres regexy. Tahle je to prilis komplikovane a je to mess. Ja jsem kdyztak nahraval ven svoji vetev tak se muzes podivat jak se to parsuje aby to bylo citelne.

Citelnost je v pythonu dulezita.

Ale jinak jako Good Job.

Je videt ze se snazis a mas potencial

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"))