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
21 changes: 21 additions & 0 deletions 1] guessing game/Hadaci hra cislo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random
def guess_the_number():
secret_number = random.randint(1, 100)

while True:
try:
user_guess = int(input("Hádej číslo: "))

if user_guess < secret_number:
print("Příliš malé!")
elif user_guess > secret_number:
print("Příliš velké!")
else:
print("Vyhráváte!")
break

except ValueError:
print("Není to číslo!")

if __name__ == "__main__":
guess_the_number()
3 changes: 3 additions & 0 deletions 1] guessing game/hadaci hra cislo/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 1] guessing game/hadaci hra cislo/.idea/hadaci hra cislo.iml

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.

4 changes: 4 additions & 0 deletions 1] guessing game/hadaci hra cislo/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 1] guessing game/hadaci hra cislo/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 1] guessing game/hadaci hra cislo/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions 1] guessing game/hadaci hra cislo/Hadaci hra cislo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import random

def hra_hadani_cisel():
vylosovane_cislo = random.randint(1, 100)

while True:
tip = input("Guess the number: ")

if not tip.isdigit():

Choose a reason for hiding this comment

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

ne takle ne, ty to mas udelat pres exception

print("It's not a number!")
continue

tip = int(tip)

if tip < vylosovane_cislo:
print("Too small!")
elif tip > vylosovane_cislo:
print("Too big!")
else:
print("You win!")
break

if __name__ == "__main__":
hra_hadani_cisel()
41 changes: 41 additions & 0 deletions 2] loto/hra lotto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import random

Choose a reason for hiding this comment

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

cely tenhle kod se mi zda opravdu velmi komplikovany. zkus si to rozdelit do funkci 1] to co vybere user 2] to co vybere pocitac 3] main

def zadej_cislo():
while True:
cislo = input("Your number (1-49): ")

if not cislo.isdigit():

Choose a reason for hiding this comment

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

stejne jako nahore

print("It's not a number!")
continue

cislo = int(cislo)

if cislo < 1 or cislo > 49:
print("Number must be in range 1-49.")
continue

return cislo

def hra_lotto():
vybrane_cisla = []
for _ in range(6):
cislo = zadej_cislo()
while cislo in vybrane_cisla:

Choose a reason for hiding this comment

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

uff.. tady mas dvojity loop. toto urcite neni spravna logika

print("This number is already chosen. Try another.")
cislo = zadej_cislo()
vybrane_cisla.append(cislo)

vybrane_cisla.sort()
print(f"Vybraná čísla: {vybrane_cisla}")

vylosovana_cisla = random.sample(range(1, 50), 6)
vylosovana_cisla.sort()
print(f"Vylosovaná čísla: {vylosovana_cisla}")

shodna_cisla = set(vybrane_cisla) & set(vylosovana_cisla)

Choose a reason for hiding this comment

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

ty z toho delas sety, to ma byt spis opacne ze do setu ukaldas..


print(f"Počet shodných čísel: {len(shodna_cisla)}")
print(f"Shodná čísla: {shodna_cisla}")


if __name__ == "__main__":
hra_lotto()
25 changes: 25 additions & 0 deletions 2] loto/lottohra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import random
def lotto_game():
user_numbers = set()

while len(user_numbers) < 6:
try:
user_input = int(input("Zadejte číslo (1-49): "))
if 1 <= user_input <= 49 and user_input not in user_numbers:
user_numbers.add(user_input)
else:
print("Neplatný vstup, zadejte platné číslo v rozsahu 1-49.")
except ValueError:
print("Neplatný vstup, zadejte platné číslo v rozsahu 1-49.")

sorted_user_numbers = sorted(user_numbers)
print("Vaše vybraná čísla:", sorted_user_numbers)

drawn_numbers = set(random.sample(range(1, 50), 6))
print("Vylosovaná čísla:", drawn_numbers)

matched_numbers = set(sorted_user_numbers).intersection(drawn_numbers)
print("Počet shodných čísel:", len(matched_numbers))

if __name__ == "__main__":
lotto_game()
8 changes: 8 additions & 0 deletions 3] guessing game 2/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 3] guessing game 2/.idea/3] guessing game 2.iml

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.

4 changes: 4 additions & 0 deletions 3] guessing game 2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 3] guessing game 2/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 3] guessing game 2/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions 3] guessing game 2/Guess game 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import random

def guessing_number2():
print("Myslim na cislo mezi 1 a 1000.")
nejnizsi = 1
nejvyssi = 1000
pokusy = 10

for i in range(pokusy):
hadane_cislo = random.randint(nejnizsi, nejvyssi)
print(f"Pocitac hada: {hadane_cislo}")

odpoved = input("Cislo je prilis male (m), prilis velke (v) nebo vyhravate (s): ")

if odpoved == "m":
nejnizsi = hadane_cislo + 1
elif odpoved == "v":
nejvyssi = hadane_cislo - 1
elif odpoved == "s":
print("Pocitac vyhral!")
break
else:
print("Neplatna odpoved. Zadejte 'm' pro prilis male, 'v' pro prilis velke nebo 's' pro vyhravate.")

else:
print("Maximalni pocet pokusu. Vyhravate!")

if __name__ == "__main__":
guessing_number2()
85 changes: 85 additions & 0 deletions 4] guessing game 3/skuska.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from flask import Flask, request

app = Flask(__name__)

HTML_START = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hadejte cislo</title>
</head>
<body>
<h1>Myslete na cislo mezi 1 a 1000</h1>
<h3>Nerikejte vase cislo ;)</h3>
<form action="" method="POST">
<input type="hidden" name="min" value="{}"></input>
<input type="hidden" name="max" value="{}"></input>
<input type="submit" value="OK">
</form>
</body>
</html>
"""


HTML = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hadejte cislo</title>
</head>
<body>
<h1>Je vase cislo {guess}?</h1>
<form action="" method="POST">
<input type="submit" name="user_answer" value="prilis velke">
<input type="submit" name="user_answer" value="prilis male">
<input type="submit" name="user_answer" value="vyhral/a jste">
<!-- <input type="submit" name="user_answer" value="vyhral/a jste"> -->
<input type="hidden" name="min" value="{min}">
<input type="hidden" name="max" value="{max}">
<input type="hidden" name="guess" value="{guess}">
</form>
</body>
</html>
"""


HTML_WIN = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hadejte cislo</title>
</head>
<body>
<h1>Huraaa! Uhodl jsem! Vase cislo je {guess}</h1>

</body>
</html>
"""


@app.route("/", methods=["GET", "POST"])
def hadejte_cislo():
if request.method == "GET":
return HTML_START.format(0, 1001)
else:
min_number = int(request.form.get("min"))
max_number = int(request.form.get("max"))
user_answer = request.form.get("user_answer")
guess = int(request.form.get("guess", 500))

if user_answer == "prilis velke":
max_number = guess
elif user_answer == "prilis male":
min_number = guess
elif user_answer == "vyhral/a jste":
return HTML_WIN.format(guess=guess)

guess = (max_number - min_number) // 2 + min_number

return HTML.format(guess=guess, min=min_number, max=max_number)


if __name__ == '__main__':
app.run()